Parse get JsonObject with Volley



试图从对象内部的行中获取值,如照片所示。但我在获取时遇到了一些问题。这是我的json文件

我正在尝试获取一些行,如"位置"或"内容">

JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, URL, null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
JSONObject jsonObject;
try {
jsonObject = new JSONObject();
String value = jsonObject.getString("location");
Log.d("test", value);
} catch (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解析Vollery json响应

最新更新