Adding link to json object in android Adding link to json object in android json json

Adding link to json object in android


PLease use JSONObject.getString('keyName') method instead of toString()

EDIT:

You should first understand why those extra \\ are showing up.It is an escape character for ".Hence,it is very much required there and is a part of JSON encoding .Hence,one should always use the above method to get values of keys whenever needed.

apart from that you can try :

JSONObject.toString(4) where 4 is actually indent spaces and see whether it helps.Otherwise there's simply no other option than to replace those extra \\ like

myJsonString.replaceAll("\\","");

or

 myJsonString=myJsonString.replaceAll("\\\\",""); 

SECOND EDIT:

The string you are sending is perfect to send to any server.You need to decode that string at the server end to JSON and then utilise it.

If you are using .NET you can see this. Or if you are on some other platform you need to find out how to decode to JSON on that platform.


There are two things going on here:

  1. Your tools are confusing you. When it shows the output:

    "{\"test2\":\"[{\\\"thumb\\\":\\\"http:\\\\\\/\\\\\\/dev.lrcdn.in\\\\\\/shiaspark\\\\\\/sites\\\\\\/default\\\\\\/files\\\\\\/512da541b31fe.jpg\\\",\\\"main\\\":\\\"http:\\\\\\/\\\\\\/dev.lrcdn.in\\\\\\/shiaspark\\\\\\/sites\\\\\\/default\\\\\\/files\\\\\\/512da541b31fe.jpg\\\"}]\"}"

    It is telling you that the result is a string containing:

    {"test2":"[{\"thumb\":\"http:\\\/\\\/dev.lrcdn.in\\\/shiaspark\\\/sites\\\/default\\\/files\\\/512da541b31fe.jpg\",\"main\":\"http:\\\/\\\/dev.lrcdn.in\\\/shiaspark\\\/sites\\\/default\\\/files\\\/512da541b31fe.jpg\"}]"}
  2. Taking that string and formatting it:

    {"test2": "[{\"thumb\":\"http:\\\/\\\/dev.lrcdn.in\\\/shiaspark\\\/sites\\\/default\\\/files\\\/512da541b31fe.jpg\",\"main\":\"http:\\\/\\\/dev.lrcdn.in\\\/shiaspark\\\/sites\\\/default\\\/files\\\/512da541b31fe.jpg\"}]"}

    We can see that you've constructed a json object containing a json-encoded string, rather than a nested jsonobject. For whatever reason, your code is having the effect of:

    JSONArray albumarray=new JSONArray();JSONObject imgobj=new JSONObject();imgobj.put("thumb", filepath.get(i));imgobj.put("main", filepath.get(i));albumarray.put(imgobj);JSONObject albumjson = new JSONObject();albumjson.put(albumname, albumarray.toString());

    That sounds like a bug in your json library