如何正确解释以字符串形式接收的JSON对象? [英] How can I interpret a JSON object received as a string correctly?
问题描述
我的Web服务已损坏,无法访问和更改.它向下发送一些主要是不错的JSON,但是属性之一是作为字符串向下发送的嵌套JSON对象.
I've got a broken web service that I can't access and alter. It sends down some mainly nice JSON, but one of the attributes is a nested JSON object that is being sent down as a string.
http://www.ireland.com/api/getitemweb/185213
以上网址的响应中的CustomJsonData就是示例.
http://www.ireland.com/api/getitemweb/185213
CustomJsonData in the response from the above url is the example.
我的问题是如何将CustomJsonData字符串解释为对象?
My question is how could I interpret the CustomJsonData string as an object?
我认为'evil'eval()可以做到,但是没有运气.
I thought the 'evil' eval() might do it, but no luck.
谢谢, 丹尼斯
推荐答案
如果使用eval,则需要在eval之前的字符串中添加(和):
If you are using eval, you need to add a ( and ) to the string before eval:
var parsedObject = eval("(" + jsonString + ")");
但是,正如您所说的,eval是邪恶的,使用来自jquery的parseJson更好(并且不需要额外的parens):
However, as you said, eval is evil, using parseJson from jquery is better (and extra parens not required):
var parsedObject = Jquery.parseJSON(jsonString);
jQuery parseJSON的文档: http://api.jquery.com/jQuery.parseJSON/
Documentation for jQuery parseJSON: http://api.jquery.com/jQuery.parseJSON/
这篇关于如何正确解释以字符串形式接收的JSON对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!