JSON serialization in Spidermonkey

梦想与她 提交于 2019-11-30 18:15:30

问题


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

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

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.)


回答1:


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.



来源:https://stackoverflow.com/questions/1055805/json-serialization-in-spidermonkey

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!