Den*_*tor 2 javascript string json eval
我有一个破坏的Web服务,我无法访问和更改.它发送一些主要是好的JSON,但其中一个属性是一个嵌套的JSON对象,它以字符串形式发送.
http://www.ireland.com/api/getitemweb/185213
来自上面url的响应中的CustomJsonData就是一个例子.
我的问题是如何将CustomJsonData字符串解释为对象?
我认为'邪恶'eval()可能会这样做,但没有运气.
谢谢,丹尼斯
如果使用eval,则需要在eval之前向字符串添加(和):
var parsedObject = eval("(" + jsonString + ")");
Run Code Online (Sandbox Code Playgroud)
但是,正如你所说,eval是邪恶的,使用jquery中的parseJson更好(并且不需要额外的parens):
var parsedObject = Jquery.parseJSON(jsonString);
Run Code Online (Sandbox Code Playgroud)
jQuery parseJSON的文档:http://api.jquery.com/jQuery.parseJSON/
| 归档时间: |
|
| 查看次数: |
5269 次 |
| 最近记录: |