Skip to content Skip to sidebar Skip to footer

Error Parsing Jsonarray Returned From .net Web Service

I have a web service implemented that returns a JSON String as follows: {'checkrecord':[{'rollno':'abc2','percentage':40,'attended':12,'missed':34}],'Table1':[]} In my Android

Solution 1:

Your result initially is not a JSONArray but rather a JSONObject.

Try this:

JSONObject jsonResult = newJSONObject(newString(reader));

JSONArray jArray = jsonResponse.getJSONArray("checkrecord");

Solution 2:

Your web service does not return pure JSON, it returns JSON as a string return value from an XML SOAP web service. In fact, it may be an error message in XML since you are not sending a valid SOAP request from the client.

Your URL needs to return raw JSON, with no SOAP XML Envelope around it. Search google for how to write JSON-based web services in ASP.NET, WCF, or another MS technology that may be familiar to you.

Edit

If you want to see the raw result of your URL, try using a tool like Fiddler to monitor the HTTP response.

Also, if you want to make SOAP web service calls from Android, check out ksoap2 for Android

Solution 3:

Try like this

JSONObject jsonobject = newJSONObject(result);
  JSONArray array = jsonobject.getJSONArray("checkrecord");
      if(array.length()>0){
          int max = array.length();
        for (int i = 0; i < max; i++) {
            JSONObject tmp = array.getJSONObject(i);
            list.add(tmp.getString("rollno"));
            mandatoryFlagList.add(tmp.getString("percentage"));
        }
     }

Post a Comment for "Error Parsing Jsonarray Returned From .net Web Service"