JSONObject initialization error

I am trying to initialize a JSONObject with the following line retrieved from a web service:

"{ "campaignid": "8", "campaignname": "Pilotarienak 2011", "campaignlink": "http:\\/\\/www.xxx.com\\/fr\\/cote-basque\\/agenda\\/2011-05-20\\/FMAAQU064FS016DV-pilotarienak-d-anglet?fromapp", "splash": "http:\\/\\/www.xxx.com\\/ads\\/customers\\/pilotarienak\\/320x480.jpg", "banner": "http:\\/\\/www.xxx.com\\/ads\\/customers\\/pilotarienak\\/320x160.jpg" }" 

This seems to be the correct json (it is checked on jsonlint.com), but when initializing a JSONObject with this, I get:

 org.json.JSONException: Value of type java.lang.String cannot be converted to JSONObject 

Can anybody help?

thanks

0
source share
3 answers

It looks like you are trying to create an instance from String with extra quotes. You need to remove the quotation marks for the wrapping (I do not use your string, but give an example to make it clearer):

This is normal:

 String jStr= "{\"param1\":\"hello\"}"; JSONObject jObj = new JSONObject(jStr); 

Is not:

 String jStr= "\"{\"param1\":\"hello\"}\""; // note this ^^ and this ^^ JSONObject jObj = new JSONObject(jStr); 
+9
source

Try rewriting everything in simplified mode (test only). I think you put some invalid character.

0
source

Try to delete all "\" characters

0
source

Source: https://habr.com/ru/post/946667/


All Articles