admin管理员组文章数量:1320656
I have a json string which is
I got this string by converting
var json = orgetd.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\"}]"
and I need to replace some symbols, I need output like that
[{"version":"1.0","minimumVersion":"0.9","channel":"/meta/handshake","supportedConnectionTypes":["long-polling","callback-polling"],"advice":{"timeout":60000,"interval":0},"id":"1"}]
means symbols to be replaced are \\
with ""
and "[
with [
and ]"
with ]
Help me if posible.
I have a json string which is
I got this string by converting
var json = org.etd.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\"}]"
and I need to replace some symbols, I need output like that
[{"version":"1.0","minimumVersion":"0.9","channel":"/meta/handshake","supportedConnectionTypes":["long-polling","callback-polling"],"advice":{"timeout":60000,"interval":0},"id":"1"}]
means symbols to be replaced are \\
with ""
and "[
with [
and ]"
with ]
Help me if posible.
Share Improve this question edited Feb 7, 2013 at 5:43 Uttara 2,5323 gold badges25 silver badges35 bronze badges asked Feb 7, 2013 at 5:19 Er KK ChopraEr KK Chopra 1,8508 gold badges33 silver badges57 bronze badges3 Answers
Reset to default 3You can simple use 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);
json.replace('\\', '')
There are no "[
in the string itself, there's just "
that define the string.
Use javascript replace function
mystring.replace(/\\/g,'').replace(/" "[ "/g,'"["')
本文标签: javascriptreplace string of json with another stringStack Overflow
版权声明:本文标题:javascript - replace string of json with another string - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742065473a2418807.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论