如何将字符串转换为JSON?

时间:2016-10-08 20:21:27

标签: json

如何将以下字符串转换为包含一些特殊字符的Json?我想要一些特定的通知网址和值进行验证。

colombiaadCallback("[{\"snippet\":\"\",\"adSlot\":\"208039\",\"section\":\"0\",\"position\":\"1\",\"ip\":\"223.165.29.225\",\"success\":-1,\"cs\":[{\"c\":\"http:\/\/ads.yahoo.com\/cms\/v1?esig=2~0e5920937f6aadb48bff63caeaefd5a0b961c753&nwid=1117471&sigv=1\",\"id\":16116},{\"c\":\"http:\/\/ade.clmbtech.com\/uid\/sync.htm?pid=19844&xid=<SSO User Id>\",\"id\":19844}],\"fpc\":\"ade1eb41-40a7-4937-9179-86ed1641f77e-10otg~1\"},{\"snippet\":\"\",\"adSlot\":\"208039\",\"section\":\"0\",\"position\":\"2\",\"ip\":\"223.165.29.225\",\"success\":-1,\"cs\":[{\"c\":\"http:\/\/ads.yahoo.com\/cms\/v1?esig=2~0e5920937f6aadb48bff63caeaefd5a0b961c753&nwid=1117471&sigv=1\",\"id\":16116},{\"c\":\"http:\/\/ade.clmbtech.com\/uid\/sync.htm?pid=19844&xid=<SSO User Id>\",\"id\":19844}],\"fpc\":\"ade1eb41-40a7-4937-9179-86ed1641f77e-10otg~1\"},{\"snippet\":\"\",\"adSlot\":\"208038\",\"section\":\"0\",\"position\":\"1\",\"ip\":\"223.165.29.225\",\"success\":-1,\"cs\":[{\"c\":\"http:\/\/ads.yahoo.com\/cms\/v1?esig=2~0e5920937f6aadb48bff63caeaefd5a0b961c753&nwid=1117471&sigv=1\",\"id\":16116},{\"c\":\"http:\/\/ade.clmbtech.com\/uid\/sync.htm?pid=19844&xid=<SSO User Id>\",\"id\":19844}],\"fpc\":\"ade1eb41-40a7-4937-9179-86ed1641f77e-10otg~1\"},{\"snippet\":\"\",\"adSlot\":\"208039\",\"section\":\"0\",\"position\":\"3\",\"ip\":\"223.165.29.225\",\"success\":-1,\"cs\":[{\"c\":\"http:\/\/ads.yahoo.com\/cms\/v1?esig=2~0e5920937f6aadb48bff63caeaefd5a0b961c753&nwid=1117471&sigv=1\",\"id\":16116},{\"c\":\"http:\/\/ade.clmbtech.com\/uid\/sync.htm?pid=19844&xid=<SSO User Id>\",\"id\":19844}],\"fpc\":\"ade1eb41-40a7-4937-9179-86ed1641f77e-10otg~1\"}]")

1 个答案:

答案 0 :(得分:1)

尝试使用JSON.parse();

var newJson = JSON.parse(myString);

在你的情况下,我用你的示例代码设置了一个变量,一切正常:

[Object, Object, Object, Object]
 0:Object
 adSlot:"208039"
 cs:Array[2]0:Object
    c:"http://ads.yahoo.com/cms/v1?esig=2~0e5920937f6aadb48bff63caeaefd5a0b961c753&nwid=1117471&sigv=1"
    id:16116
    __proto__:Object.......