我真的是Android上的新手,正在登录系统上工作,我正在使用凌空发布数据....我遇到的问题是当我尝试读取响应时。 .. 响应如下所示:
{“ st”:“否”,“消息”:“错误”}
我正在尝试仅访问st或message,有没有办法做到这一点?我尝试做:
response [i] ----发现扩展了数组类型'org.json.JSONObject'
JsonObjectRequest jsonRequest = new JsonObjectRequest(Request.Method.POST, url, params, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.e(TAG, "Response: " + response.length());
for (int i = 0; i < response.length(); i++) {
Log.e(TAG, "Values: " + response);
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
error.printStackTrace();
}
});
Volley.newRequestQueue(this).add(jsonRequest);
答案 0 :(得分:2)
您可以使用
response.getString("Message")
从给定的JSON获取消息
答案 1 :(得分:1)
Sub FindPl()
dim i as long, wb as workbook, OUTPUTRANGE as range, SEARCHRANGE as range
set wb = "C:\Users\chenj5\Documents\Meeting_Jan_2019\simulation of Z1.9 for Ultra Multi-Focal\Meeting 0220\Dataset used for simulation.xlsx" 'added xlsx extension
with wb
set OUTPUTRANGE = .range(.cells(5,"D"),.cells(100,"D")) 'guessed... the range with the desired output
set SEARCHRANGE = .range(.cells(5,"B"),.cells(100,"B")) 'guessed... the range where you will find .cells(i,"DE")
end with
with activeworkbook.sheets(1) 'FIX THIS TO FIT YOUR NEEDS
For i = 2 To 1730
If .Cells(i, "DE").Value > 3.9 Then 'FIXED SYNTAX ERROR
.Cells(i, "DI").Value = 0
Else:
.Cells(i, "DI").Value = Application.Index(OUTPUTRANGE, Application.Match(.cells(i, "DE").value,SEARCHRANGE, 0))
End If
Next
end with
End Sub
重要的是要捕获json异常,以防万一响应字符串无法转换为json对象。然后使用getString()从创建的json对象获取消息。