如何在Android中从JSON对象访问数据?
我的JSONObject:如何在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 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
上的方法。