rencsaridogan rencsaridogan - 4 years ago 147
JSON Question

JSON, Link Gets Broken

I'm using JSON for some Android Application. I am trying to store links in JSON but they are getting broken inside JSON like below :

11-21 01:15:52.080: D/output(3775): "video_url": "http:\/\/love.com\/bunny.mp4",


I'm putting data like below :

jsonObject.put("thumb", "http://love.com//poster.jpg");
jsonObject.put("url", "http://love.com/bunny.mp4");
jsonObject.put("name", "Bunny");
jsonArray.put(jsonObject);


Anybody has any ideas about this problem?

Answer Source

The strings in JSON are getting escaped. You can either write a simple function to unescape them yourself or use a library which has built in functions like GSON or Jackson.

I personally used this library in the past

http://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringEscapeUtils.html

It provides a function: unescapeJson(String) which will give you your original links back. Just include it in your project and call the method.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download