Reputation: 1850
I have a json string which is
I got this string by converting
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\"}]"
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.
Upvotes: 4
Views: 12380
Reputation: 4711
Use javascript replace function
mystring.replace(/\\/g,'').replace(/" "[ "/g,'"["')
Upvotes: 0
Reputation: 911
You 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);
Upvotes: 3
Reputation: 191809
json.replace('\\', '')
There are no "[
in the string itself, there's just "
that define the string.
Upvotes: 0