0

i have the json which receives json from my web service. Which will be look like this,

{"JSONDataResult":"[{\"id\":3,\"e_code\":123533,\"type\":\"ab\",\"description\":\"sick-leave\",\"remarks\":\"test\",\"req_date\":\"2016-07-01T12:22:34\",\"date\":\"01\/07\/2016\",\"response\":null,\"aproved_date_time\":null,\"status\":\"not seen\"}]"}

when validating it from json http://www.jsoneditoronline.org/ it says it has only one object . I cant even convert it into a json Array from client android app it says like this

 org.json.JSONException: Value [{"id":3,"e_code":123533,"type":"ab","description":"sick-leave","remarks":"test","req_date":"2016-07-01T12:22:34","date":"01/07/2016","response":null,"aproved_date_time":null,"status":"not seen"}] at JSONDataResult of type java.lang.String cannot be converted to JSONArray

Iam using AsyncHttpClient (loopj) to parse json

client.get("http://192.168.1.6/JSONService/RESTService.svc/json/dddd",new JsonHttpResponseHandler(){
        @Override
        public void onSuccess(int statusCode, Header[] headers, JSONObject response) {


                try {

                    String str=response.toString();

                    JSONObject jobj=new JSONObject(str);
                    jsonArray=jobj.getJSONArray("JSONDataResult");

                    ...
noushad
  • 11
  • 2
  • 1
    sorry it was a duplicate question of [this](http://stackoverflow.com/questions/15945394/android-value-of-type-java-lang-string-cannot-be-converted-to-jsonarray) – noushad Jul 08 '16 at 05:37
  • why do you want to convert the json to string again? why dont you parse it directly?? – SripadRaj Jul 08 '16 at 05:37
  • i found the answer there... – noushad Jul 08 '16 at 05:38
  • The JSON *is* an object with a single element, whose value is a *string*, that is in itself JSON. So you'll have to parse it twice. If you have any control over the producer I'd suggest changing it. – Biffen Jul 08 '16 at 06:19

1 Answers1

0

You can parse it by below way :

Let's say you are getting response in below variable as strData

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

  JSONObject jsonObject = new JSONObject(strData);
  JSONArray jsonArray = jsonObject.getJSONArray("JSONDataResult");
Vickyexpert
  • 3,147
  • 5
  • 21
  • 34