Android 用截击法解析get JsonObject
正在尝试从对象内部的行中获取值,如图所示。但获取时遇到一些问题 我正在尝试获取一些行,如“位置”或“内容”Android 用截击法解析get JsonObject,android,json,android-volley,Android,Json,Android Volley,正在尝试从对象内部的行中获取值,如图所示。但获取时遇到一些问题 我正在尝试获取一些行,如“位置”或“内容” JsonObjectRequest-request=newjsonobjectrequest(request.Method.GET,URL,null, 新的Response.Listener(){ @凌驾 公共void onResponse(JSONObject响应){ JSONObject JSONObject; 试一试{ jsonObject=新的jsonObject(); 字符串值=
JsonObjectRequest-request=newjsonobjectrequest(request.Method.GET,URL,null,
新的Response.Listener(){
@凌驾
公共void onResponse(JSONObject响应){
JSONObject JSONObject;
试一试{
jsonObject=新的jsonObject();
字符串值=jsonObject.getString(“位置”);
Log.d(“测试”,值);
}捕获(JSONException e1){
e1.printStackTrace();
}
试试这个
JSONObject photo;
{
try {
photo = response.getJSONObject("photo");
JSONObject owner = photo.getJSONObject("owner");
JSONObject title = photo.getJSONObject("title");
String _content = title.getString("_content");
String location = owner.getString("location");
} catch (JSONException e) {
e.printStackTrace();
}
}
另外,请查看本博客,了解如何解析json@vpedro72如果它解决了您的问题,请不要忘记接受答案。
JSONObject photo;
{
try {
photo = response.getJSONObject("photo");
JSONObject owner = photo.getJSONObject("owner");
JSONObject title = photo.getJSONObject("title");
String _content = title.getString("_content");
String location = owner.getString("location");
} catch (JSONException e) {
e.printStackTrace();
}
}