【发布时间】:2016-09-15 17:06:46
【问题描述】:
我在 android 中使用 JSON 获取数据时遇到问题: Nonplus 的问题是:该代码可以与另一个 url 一起使用,但它不适用于我的 url ,我已经从服务器获取数据,就像这张图片 json data with php from browser
和安卓代码
all metter in ( jArray = new JSONArray(result1) ) 它不起作用 & get's exception with my case ......
JSONObject json_data=null;
try {
jArray = new JSONArray(result1);
for (int i = 0; i < jArray.length() - 1; i++) {
json_data = jArray.getJSONObject(i);
String name = json_data.getString("name");
String specializes = json_data.getString("type");
String info = json_data.getString("type");
String address = json_data.getString("address");
String email = json_data.getString("email");
double x_position = json_data.getDouble("position_x");
double y_position = json_data.getDouble("position_y");
int phone = json_data.getInt("telephone");
}
result2 = jArray.toString()+ ""; }
catch (JSONException e) {
e.printStackTrace();
}
这是php代码
<?php
require "database2.php";
//$Desname= $_POST["DesaseName"];
$Desname= "Apoplexy";
$r[]='';
$mysgl_query = "SELECT * FROM desases as t1 LEFT JOIN `departments` as t2
ON `department_id` = dep_id and desase_name = 'Apoplexy'
LEFT JOIN hospital_info as t3 ON `hosid` = `id` ;";
$result = mysqli_query($conn,$mysgl_query);
$row = mysqli_fetch_array($result);
while($row = mysqli_fetch_array($result))
{
$r[]=$row;
}
print(json_encode($r));
?>
【问题讨论】:
-
您的 JSON 数组看起来无效。它应该只包含一个 JSON 对象的“数组”。但是在您的 JSON 数组中,它在数组中包含无效数据“”。
-
你的json格式不对
-
是的,你是对的 mr.Weava 和 mr.siddhesh,我解决了,非常感谢..