【发布时间】:2019-05-15 23:41:46
【问题描述】:
我得到以下我需要解析的 JSON 字符串:
response => {
"error":false,
"uid":39,
"user":{
"name":"my username",
"email":"solinpromey@gmail.com",
"created_at":"2019-05-15 13:22:19",
"updated_at":null,
"imagen":null,
"nombre":null,
"apellidos":null,
"nivel_usuario":null,
"id_usuario":39,
"unique_id":null,
"verified":null,
"cel_verificado":null,
"tel":"123456789",
"code_cel":null
}
}
我需要获取关键用户内部字段的值。
我正在尝试如下,但没有工作:
String errorMsg = jObj.getString("error_msg");
这里我遇到了一个异常:
W/System.err: org.json.JSONException: No value for error_msg
因此,以下行不会被执行:
JSONObject jObj = new JSONObject(response);
JSONObject user = jObj.getJSONObject("user");
String email = user.getString("email");
Log.d("RESPUESTA", "RESPUESTA email" + email);
【问题讨论】:
-
您的回复中没有名为
"error_msg"的字段。也许是“错误”?并且这个字段的类型是boolean,而不是string。