Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>mysql_fetch_assoc</code> returns an array. So in your code you get something like:</p> <pre><code> echo json_encode(array('Course' =&gt; array())); </code></pre> <p>the result is a string: <code>{"Course":[]}</code>. In JSON this is an object. so you need to fetch it with:</p> <pre><code>JSONObject jsonObject = new JSONObject(jsonString); JSONArray jArray = jsonObject.getJSONArray("Course"); </code></pre> <p>See also: <a href="https://stackoverflow.com/questions/4244879/reading-a-json-array-in-android">Reading a Json Array in android</a></p> <p><strong>update</strong></p> <p>in your php:</p> <pre><code>function verifyCourse($courseCode){ $result = mysql_query("SELECT * FROM Course WHERE CourseCode = \"$courseCode\" LIMIT 1"); $rows = array(); while ($r = mysql_fetch_assoc($result)) { $rows[]= $r; } header('Content-type: application/json'); return json_encode(array('Course' =&gt; $rows)); exit; } </code></pre> <p>Which outputs a string like:</p> <pre><code> {"Course":[{"key1":"value1","key2":"value2"},{"2key1":"2value1","2key2":null}]} </code></pre> <p>in your java code:</p> <pre><code> JSONObject jsonObject = new JSONObject(builder.toString()); JSONArray jArray = jsonObject.getJSONArray("Course"); for(int i = 0; i &lt; jArray.length(); i++){ JSONObject jObject = jArray.getJSONObject(i); Iterator&lt;String&gt; keys = jObject.keys(); storage = new HashMap&lt;String, String&gt;(); while( keys.hasNext() ){ String key = (String)keys.next(); storage.put(key, jObject.get(key).toString()); } results.add(storage); } </code></pre>
    singulars
    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. VO
      singulars
      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