Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Android中检索JSONobject响应特定值_Android_Json - Fatal编程技术网

如何在Android中检索JSONobject响应特定值

如何在Android中检索JSONobject响应特定值,android,json,Android,Json,我想将JSONobject响应的特定值存储在一个变量中。 我的JSON响应是一个字符串: {"username":"admin","password":"admin","mobile":"xxxxxxxxxx"} 我想从这个回复中检索手机号码 有人能帮忙吗?你的Json是 {“用户名”:“管理员”,“密码”:“管理员”,“手机”:“XXXXXXXXX”} 轻松解析它 JSONObject jsonObject= new JSONObject(json_response); String m

我想将JSONobject响应的特定值存储在一个变量中。 我的JSON响应是一个字符串:

{"username":"admin","password":"admin","mobile":"xxxxxxxxxx"}
我想从这个回复中检索手机号码

有人能帮忙吗?

你的Json是

{“用户名”:“管理员”,“密码”:“管理员”,“手机”:“XXXXXXXXX”}

轻松解析它

 JSONObject jsonObject= new JSONObject(json_response);
 String mobile= jsonObject.optString("mobile");

您需要执行以下操作:

final JSONObject jsonObject = new JSONObject(response);
if (jsonObject.length() > 0) {
 String mobile  = jsonObject.optString("mobile");
 Log.e("TAG", "mobile:"+mobile);
}

使用asynchttpclient库。它易于使用和解析值

在app gradle中添加此行

compile 'com.loopj.android:android-async-http:1.4.9'
那么


到目前为止您尝试了什么?我收到了来自服务器的json格式的响应,sring{username:“admin”,“password:“admin”,“mobile:“xxxxxxxxx”},现在我想检索一个特定的密钥。为此,我使用了jsonobject
Let, String s = "{"username":"admin","password":"admin","mobile":"xxxxxxxxxx"}";

JSONObject jsonObject = new JSONObject(s);
String username = jsonObject.optString("username");
String mobile = jsonObject.optString("mobile");
String password = jsonObject.optString("password");