一个错误说 java.lang.string 无法转换为 jsonobject,如何将其转换为 jsonobject
这是我的 PHP 代码:
<?php
mysql_connect("localhost","root","");
mysql_select_db("mydatabase");
$query = "SELECT SUM(OrderPrice) as total FROM tbl_user";
$result = mysql_query($query);
while($row = mysql_fetch_assoc($result))
{
$new_arr[] = $row['total'];
}
echo json_encode($new_arr);
?>
我的安卓代码:
try{
JSONArray jArray = new JSONArray(result);
for(int i=0;i<jArray.length();i++){
JSONObject json_data = jArray.getJSONObject(i);
Log.i("log_tag","total: "+json_data.getString("total"));
total.setText("total");
}
}catch(JSONException e){
Log.e("log_tag", "Error parsing data " + e.toString());