Spidermonkey中的JSON序列化 [英] JSON serialization in Spidermonkey

查看:58
本文介绍了Spidermonkey中的JSON序列化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 python-spidermonkey 来运行JavaScript代码。

I'm using python-spidermonkey to run JavaScript code.

为了传递对象(而不是只是字符串)到Python,我正在考虑返回一个JSON字符串。

In order to pass objects (instead of just strings) to Python, I'm thinking of returning a JSON string.

这似乎是一个常见的问题,所以我想知道这个内置是否有任何设施进入Spidermonkey或 python-spidermonkey
(我知道 uneval 但这并不意味着用于JSON序列化 - 我宁愿避免注入一块JavaScript来执行此操作。 )

This seems like a common issue, so I wonder whether there are any facilities for this built into either Spidermonkey or python-spidermonkey. (I do know about uneval but that is not meant to be used for JSON serialization - and I'd rather avoid injecting a block of JavaScript to do this.)

推荐答案

我会使用JSON.stringify。它是ECMAScript 5标准的一部分,它是在当前版本的spidermonkey中实现的。我不知道它是否在python-spidermonkey使用的版本中,但如果不是,你可以从 http://www.json.org/js.html

I would use JSON.stringify. It's part of the ECMAScript 5 standard, and it's implemented in the current version of spidermonkey. I don't know if it's in the version used by python-spidermonkey, but if it isn't, you can get a JavaScript implementation from http://www.json.org/js.html.

这篇关于Spidermonkey中的JSON序列化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆