Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON error "Value at result of type java.lang.String cannot be converted to JSONArray" in android
    primarykey
    data
    text
    <p>I used the <a href="http://p-xr.com/android-tutorial-how-to-parse-read-json-data-into-a-android-listview/" rel="nofollow">link</a> for JSON RPC. I am getting a response as expected. But when i try to parse the response, it's giving me json error.</p> <p>My code:</p> <pre><code>JSONEntity entity = new JSONEntity(jsonRequest); HttpPost request = new HttpPost("http://192.168.1.150/jsondemo12/service.asmx"); request.setEntity(entity); HttpResponse response = httpClient.execute(request); StatusLine statusLine = response.getStatusLine(); int statusCode = statusLine.getStatusCode(); if (statusCode == 200) { HttpEntity httpEntity = response.getEntity(); InputStream content = httpEntity.getContent(); BufferedReader reader = new BufferedReader( new InputStreamReader(content,"iso-8859-1"),8); String line; while ((line = reader.readLine()) != null) { builder.append(line); } content.close(); } else { Log.e(AndroidJSONActivity.class.toString(), "Failed to download file"); } strJSONValue=builder.toString(); txtViewParsedValue.append("\n+++++++++++++\n"+strJSONValue+"\n"); try { parseJSON(); } catch (JSONException e) { Log.e("error","Error while parsing!!!"); e.printStackTrace(); } Log.e("response", strJSONValue); public void parseJSON() throws JSONException { String attr1="",attr2=""; jsonObject = new JSONObject(strJSONValue); JSONArray result = jsonObject.getJSONArray("result"); &lt;- Error in this line!!! for(int i=0;i &lt; result.length();i++){ JSONObject e = result.getJSONObject(i); attr1 = "ExhibitorID: "+ e.getString("ExhibitorID"); attr2 = "ExhibitorName: "+e.getString("ExhibitorName"); } strParsedValue=attr1+"\n"+attr2; Log.d("Parse", attr1); Log.d("Parse", attr2); txtViewParsedValue.append("\n**********\nParsed Value: \n"); txtViewParsedValue.append(strParsedValue); } </code></pre> <p>The result i get in "strJSONValue" is string format, without the starting and ending double quotes. Like: </p> <pre><code>{"id":2,"result":"[ {\"ExhibitorID\":42, etc....} ]"} </code></pre> <p>The result string is as per requirement,but i am not able to parse the string into the JSON Object as per requirement. It gives error in Logcat: <code>org.json.JSONException: Value &lt;content of the string&gt; at result of type java.lang.String cannot be converted to JSONArray</code></p> <p>Please help me. Thanks</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload