Generally, I post a requet to PHP server to query a mysql table's data set and then it will send back to Andorid to parsing the resonse string(a JSONArray string) without problem. The PHP code section used is as below:
....
if($result = mysql_query($sql, $link))
{
if (mysql_num_rows($result) != 0)
{
while($row2 = mysql_fetch_array($result,MYSQL_ASSOC))
{
$data[]=$row;
}
}
}
print_r(urlencode(json_encode($data)));
if (is_resource($result))
mysql_free_result($result);
mysql_close($link);
However, if I add one more pars of key-value string to $data array after completing sql query by using the method in php code below:
$data['new_key'] = "new_value";
There will have the JSONArry Exception prompt in android side while parsing the new JSONArray String: ..... (The value part is double bytes' Chinese Characters)
Value {"new_key":"new_value","0":{"old_key1":"old_value1" ,"old_key2":"old_value2","old_key3":"old_value3",.....}} of type org.json.JSONObject cannot be converted to JSONArray
If you don't mind, please help and point me out where I was wrong and how to solve it, thanks !