【发布时间】:2015-05-08 15:45:33
【问题描述】:
我正在尝试处理 json 响应,就像
{"Status":true,"UserId":111,"FirstName":"dev","LastName":"dev","Gender":-1,"BirthdayDate":"0000-00-00","Phone":"","ProfilePicture":"","ProfilePicture60px":"","ProfilePicture120px":"","CountryId":-1,"Email":"droidwithmxxmail.com","Password":"******123","RegisterDate":"2015-05-08 20:08:07","SessionId":"fce248fe6499b7a9338a1b64554509eb77841"}
但得到org.json.JSONException: no value for exception
我的代码是这样的。
if (jsonStr != null) {
try {
JSONObject jsonObj = new JSONObject(jsonStr);
allres =jsonObj.getJSONArray(jsonStr);
for (int i = 0; i < allres.length(); i++) {
JSONObject c = allres.getJSONObject(i);
userId = c.getString("UserId");
}
} catch (JSONException e) {
e.printStackTrace();
}
【问题讨论】:
-
你确定这就是解析的全部代码吗?
-
当然不是。我只是发布了响应代码
-
根据您的代码,您首先要查找一个数组,然后是单个对象,但是您的示例 json 中没有数组?
-
回复就像我首先发布的一样。但不知道如何处理。
-
尝试删除jsonarray代码并像jsonobject一样使用它,或者只是删除JSONObject jsonObj = new JSONObject(jsonStr);和用户 allres = new JSONArray(jsonStr)
标签: json android-json