Android Json错误org.Json.JSONException:没有值
它给了我错误日志:“org.json.JSONException:tableData没有值”Android Json错误org.Json.JSONException:没有值,android,json,Android,Json,它给了我错误日志:“org.json.JSONException:tableData没有值” 对象UserListByBusinessAreaContextResult包含一个字符串。此字符串是: "{\"tableData\":[{\"UserID\":30,\"Username\":\"Teste\",\"Name\":\"Teste\"}]}" 你注意到报价了吗?问题是,WCF服务返回的是JSON字符串,而不是对象。因此,要么您必须更改WCF服务以交付对象,要么重新解析该字符串。像这样(
对象
UserListByBusinessAreaContextResult
包含一个字符串。此字符串是:
"{\"tableData\":[{\"UserID\":30,\"Username\":\"Teste\",\"Name\":\"Teste\"}]}"
你注意到报价了吗?问题是,WCF服务返回的是JSON字符串,而不是对象。因此,要么您必须更改WCF服务以交付对象,要么重新解析该字符串。像这样(未测试):
UserListByBusinessAreaContextResult
值是JSON,即您的JSON是双重编码的。您是否生成了JSON?否,我从wcf serviceWell收到json,因为UserListByBusinessAreaContextResult
是json,您还必须对其进行解码才能到达其中的数组。查看gson进行反序列化可以让生活更轻松。
{
"UserListByBusinessAreaContextResult": "{\"tableData\":[{\"UserID\":30,\"Username\":\"Teste\",\"Name\":\"Teste\"}]}"
}
"{\"tableData\":[{\"UserID\":30,\"Username\":\"Teste\",\"Name\":\"Teste\"}]}"
JSONObject mainJson22 = new JSONObject(reply);
JSONObject tableData = new JSONObject(
mainJson22.getString("UserListByBusinessAreaContextResult"));