它给了我错误日志:“org.json.JSONException:tableData没有值”
try {
JSONObject mainJson22 = new JSONObject(reply);
JSONObject jsonResult = mainJson22.getJSONObject("UserListByBusinessAreaContextResult");
JSONArray jsonArray22 = jsonResult.getJSONArray("tableData");
// JSONArray jsonArray22 = mainJson22.getJSONArray("UserListByBusinessAreaContextResult"); // JSONArray jsonArray22 = jsonResult.getJSONArray("tableData"); Log.i("mainjson234","" + jsonArray22);
for (int i2 = 0; i2 < jsonArray22.length(); i2++) {
JSONObject objJson22 = jsonArray22.getJSONObject(i2);
错误在线:`“JSONArray jsonArray22 = jsonResult.getJSONArray(”tableData“);”
继承人json:
{
"UserListByBusinessAreaContextResult": "{\"tableData\":[{\"UserID\":30,\"Username\":\"Teste\",\"Name\":\"Teste\"}]}"
}
答案 0 :(得分:0)
对象UserListByBusinessAreaContextResult
包含一个字符串。这个字符串是:
"{\"tableData\":[{\"UserID\":30,\"Username\":\"Teste\",\"Name\":\"Teste\"}]}"
你注意到引号了吗?问题是,您的WCF服务返回JSON字符串,而不是对象。因此,要么您必须更改WCF服务以提供对象,要么再次解析该字符串。像这样(未经测试):
JSONObject mainJson22 = new JSONObject(reply);
JSONObject tableData = new JSONObject(
mainJson22.getString("UserListByBusinessAreaContextResult"));