我有一个json字符串,它是
我通过转换得到这个字符串
var json = org.cometd.JSON.toJSON(envelope.messages);
"[{\"version\": \"1.0\", \"minimumVersion\": \"0.9\", \"channel\": \"/meta/handshake\", \"supportedConnectionTypes\": [\"long-polling\", \"callback-polling\"], \"advice\": {\"timeout\": 60000, \"interval\": 0}, \"id\": \"1\"}]"我需要替换一些符号,我需要这样的输出
[{"version":"1.0","minimumVersion":"0.9","channel":"/meta/handshake","supportedConnectionTypes":["long-polling","callback-polling"],"advice":{"timeout":60000,"interval":0},"id":"1"}]表示要替换的符号是带有""的\\、带有[的"[和带有]的]"
如果可能的话,请帮帮我。
发布于 2013-02-07 13:23:01
您可以简单地使用Json.Parse()
var json = "[{\"version\": \"1.0\", \"minimumVersion\": \"0.9\", \"channel\": \"/meta/handshake\", \"supportedConnectionTypes\": [\"long-polling\", \"callback-polling\"], \"advice\": {\"timeout\": 60000, \"interval\": 0}, \"id\": \"1\"}]"
JSON.Parse(json);发布于 2013-02-07 13:22:19
json.replace('\\', '')字符串本身没有"[,只有定义字符串的"。
发布于 2013-02-07 13:23:41
使用javascript replace function
mystring.replace(/\\/g,'').replace(/" "[ "/g,'"["')https://stackoverflow.com/questions/14744101
复制相似问题