【发布时间】:2019-04-09 10:51:02
【问题描述】:
我有一个 RESTful API 在我的本地机器上运行,它根据请求返回 JSON 响应(实际上这个 JSON 是 nodejs Soap 客户端请求的响应)。对于这种特殊情况,我收到来自 Android 客户端的 POST 请求并返回以下响应:
{
QueryAcctBalResponse: {
BalExDtoList: {
BalExDto: [{
BalID: "xxxx",
AcctResID: "xxxx",
AcctResName: "xxxx",
BalType: "xxxx",
Balance: "xxxx",
EffDate: "xxxx",
ExpDate: "xxxx",
UpdateDate: "xxxx"
}, {
BalID: "yyyy",
AcctResID: "yyyy",
AcctResName: "yyyy",
BalType: "yyyy",
Balance: "yyyy",
EffDate: "yyyy",
ExpDate: "yyyy",
UpdateDate: "yyyy"
}]
}
}
}
问题是每次我尝试解析该响应并在 android 中显示此信息(特别是“AcctResName”)。我得到 org.json.JSONException: BalExDto 没有价值。我在 android 中使用 Volley Libray 来解析 Json,我使用了 Jsonobject 请求。
请求代码。
JsonObjectRequest sq = new JsonObjectRequest(Request.Method.POST, balanceUrl, request, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONArray jsonArray = response.getJSONArray("BalExDto");
for (int i = 0; i < jsonArray.length(); i++){
JSONObject jsonObject=jsonArray.getJSONObject(i);
Toast.makeText(CheckBalance.this, ""+jsonObject.get("AcctResName"), Toast.LENGTH_LONG).show();
}
pd.hide();
} catch (JSONException e) {
e.printStackTrace();
}
Log.d("Response", "Response_TAG: "+response);
}
【问题讨论】:
标签: android json android-volley