Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.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中从JSON对象访问数据?_Android_Json - Fatal编程技术网

如何在Android中从JSON对象访问数据?

如何在Android中从JSON对象访问数据?,android,json,Android,Json,我的JSONObject: JSONObject callback = {"message": "message here", "response": "response here"} 我想从json的respone字符串中获取响应。 我尝试了以下方法: JSONObject response = callback.getJSONObject("response"); String message = next.getString("response"); 我得到了类似于字符串和JSONOb

我的JSONObject:

JSONObject callback = {"message": "message here", "response": "response here"}
我想从json的respone字符串中获取响应。 我尝试了以下方法:

JSONObject response = callback.getJSONObject("response");
String message = next.getString("response");
我得到了类似于字符串和JSONObject转换问题的错误

JSONObject回调={“message”:“message here”,“response”:“response here”}

您需要访问响应值,如下代码所示

String response = callback.getString("response");
尝试如下:

JSONObject callback = {"message": "message here", "response": "response here"}

String response = callback.getString("response");
String message = callback.getString("message");

我不同意,我不想使用第三方图书馆。我只是想通过使用JSONObject的方式访问这个变量。“response”保存JSONObject或字符串?@sark9012好吧,答案不仅是关于第三方库的,还有很多教程和其他链接,展示了如何正确使用
JSONObject
上的方法。