【发布时间】:2018-08-06 01:33:16
【问题描述】:
到目前为止,我可以向服务器发送一个 Get 请求,并在 url 中添加一个字母:
private void GetDevice() {
String deviceId = editTextDeviceId.getText().toString().trim();
if(TextUtils.isEmpty(deviceId)){
editTextDeviceId.setError("Please enter deviceId");
editTextDeviceId.requestFocus();
}
HashMap<String, String>params = new HashMap<>();
params.put("deviceID", deviceId);
PerformNetworkRequest request = new PerformNetworkRequest(Api.URL_GETBYDEVICEID + deviceId, null, CODE_GET_REQUEST);
request.execute();
}
当我按下“搜索”按钮时,它会发送请求:
buttonSearch.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
GetDevice();
}
});
服务器响应是 JSONArray :
W/System.err: org.json.JSONException: Value [{"DeviceId":"T","TransactionValue":2,"RSSI":2,"Time":"2018-08-02T14:43:00"}] of type org.json.JSONArray cannot be converted to JSONObject
这是我的问题。 根据我的阅读,我知道我需要使用 ArrayList 和 ArrayAdapter 将其转换为 JSONObject。到目前为止我是对的吗?
这就是我卡住的地方,因为我不知道该怎么做。
非常感谢!
【问题讨论】:
-
看起来您正在尝试将字符串 json 转换为 JSONObject,但字符串结果是 JSONArray
-
我的意思是这是我理解的,但在这一点上我很困惑。
-
您的列表数据适配器是什么样的?
标签: java android json arraylist