【发布时间】:2017-10-16 12:02:21
【问题描述】:
我想将php代码发送的json数组存储在android的java数组中。我的 php 代码运行良好,但在应用程序中我得到 name: 作为输出。我想在 texview 中显示名称以进行检查。我也想通过一个一个地访问它们来处理这些名字。
php代码:
echo json_encode(array("result"=>$result));
Java 代码:
public class Salary {
public static final String DATA_URL1 = "http://********.com/name.php?salary=";
public static final String KEY_name = "name";
public static final String JSON_ARRAY1 = "result";
}
这是我的Name.java的一个方法
private void showJSON(String response) {
String name = "";
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray result = jsonObject.getJSONArray(Salary.JSON_ARRAY1);
for (int i = 0; i < result.length(); i++) {
JSONObject collegeData = result.getJSONObject(i);
name = collegeData.getString(Salary.KEY_name);
}
} catch (JSONException e) {
e.printStackTrace();
}
textViewResult1.setText("Name:\t" + name);
}
【问题讨论】:
-
请你把得到的示例json结果字符串作为响应。
-
有什么问题?你想存储数据?文本不显示在您的文本视图中?
-
我要存储数据..
-
使用google介绍的Gson。