0

Json response should look like :

"{\"syncrequest\":{\"user\":{\"@xmlns:xsi\":\"http://www.w3.org/2001/XMLSchema-instance\",\"active\":\"true\",\"basedataset\":\"false\"},\"syncversion\":\"89\",\"syncdata\":[{\"operation\":\"INSERT OR REPLACE\",\"table\":\"WSInformation\",\"rows\":[{\"WS_ID\":\"71\",\"WS_ParentOwn\":null,\"WS_Notes\":\"Notes\\"for\\"VistaStore Fleet\\"save\",\"CC_ID\":\"1\",\"Record_Instance\":\"1\",\"Record_LastModified\":\"2013-11-26T07:51:35.203\"}]}]}}"

Response coming from server with a string format. When i convert the above string in json format using

       JsonObject jObject =new JsonObject(string);

its getting error like unterminated character in string.

Can any body help me out for above problem.

Thanks In advance

Edited :

The response coming from server is in the form of input stream .

So, I used to convert the inputstream to string using the function :

     IOUtils.readStream(instream);

Then the response string should like :

string response =

"{\"syncrequest\":{\"user\":{\"@xmlns:xsi\":\"http://www.w3.org/2001/XMLSchema-instance\",\"active\":\"true\",\"basedataset\":\"false\"},\"syncversion\":\"89\",\"syncdata\":[{\"operation\":\"INSERT OR REPLACE\",\"table\":\"WSInformation\",\"rows\":[{\"WS_ID\":\"71\",\"WS_ParentOwn\":null,\"WS_Notes\":\"Notes\\"for\\"VistaStore Fleet\\"save\",\"CC_ID\":\"1\",\"Record_Instance\":\"1\",\"Record_LastModified\":\"2013-11-26T07:51:35.203\"}]}]}}"

By using the below function to form the json object,I removing the double quotes.

res = response.substring(1, response.length() - 1);

and removing double quotes with in the string using the below function.

res = response.replace("\\"", "\"");

Abu Yousuf
  • 5,729
  • 3
  • 31
  • 50
Kumar Kalluri
  • 493
  • 2
  • 6
  • 26

2 Answers2

0

Don't use JsonObject in conversion.

     JSONObject jObject = new JSONObject(response);
     JSONArray jArray = jObject.getJSONArray("syncrequest");

import this org.json.JSONObject;

not com.google.gson.JsonObject;

Arunkumar
  • 103
  • 1
  • 12
0

I think it's not a valid JSON-object.

none
  • 1,699
  • 2
  • 13
  • 18
  • Maybe you have to specify something like this befor reading stream - setContentType("application/json") ? – none Nov 26 '13 at 09:35