Note that there are some explanatory texts on larger screens.

plurals
  1. POJSON exception in Android
    text
    copied!<p>I am trying to execute query on database in the localhost and send the JSON object to the client in android. I m not been able to know what is the problem in my code. So some one please help me on this regard.</p> <p>My php code is the one where i m sending the JSON object. <em>php code</em></p> <p>query executed successfully..</p> <pre><code>$row=mysql_fetch_array($result1); $email=$row['EM']; $pass=$row['PASS']; $post=array("email"=&gt;$email, "pass"=&gt;$pass); $posts[] = array("post"=&gt;$post); //echo "SUCCESS"; header('Content-type: application/json'); echo json_encode(array("posts"=&gt;$posts)); </code></pre> <p>And in android side i ve this code below;</p> <pre><code>HttpResponse response = doPost(url, kvPairs); String responseBody=response.toString(); String temp = EntityUtils.toString(response.getEntity()); if (temp.compareTo("SUCCESS")==0) { Toast.makeText(this, "Working", Toast.LENGTH_LONG).show(); } </code></pre> <p>Above part executes .. Below code throws a JSON exception</p> <pre><code> JSONObject json = new JSONObject(responseBody); JSONArray jArray = json.getJSONArray("posts"); no_of_obj=jArray.length(); nemail=new String[no_of_obj]; npass=new String[no_of_obj]; for (int i = 0; i &lt; jArray.length(); i++) { JSONObject e = jArray.getJSONObject(i); String s = e.getString("post"); JSONObject jObject = new JSONObject(s); Toast.makeText(context,jObject.getString("email")+":"+jObject.getString("pass") , duration).show(); nemail[i]=jObject.getString("email"); npass[i]=jObject.getString("pass"); } </code></pre> <p>In the log cat i can see : The json string must begin with "{"....</p>
 

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