这是eclipse中的代码:
JSONObject j = new JSONObject(getRequest(myUrl));
JSONArray jArray = j.getJSONArray("data");
for (int i = 0; i < jArray.length(); i++) {
sret += jArray.getJSONObject(i).getString("NO_CUST").toString();
}
这是PHP中的代码:
$result = mssql_query($query, $conn) or die('Errorquery: '.$query);
$rows = array();
while ($r = mssql_fetch_assoc($result)) {
$rows[] = $r;
}
$data = "{data:".json_encode($rows)."}";
echo $data;
Logcat:
03-07 16:05:58.504: W/System.err(821): org.json.JSONException: Value <br of type java.lang.String cannot be converted to JSONObject
为什么?
答案 0 :(得分:0)
而不是
$data = "{data:".json_encode($rows)."}";
echo $data;
使用
print(json_encode($data));