使用 Volley 解析获取 JsonObject
Parse get JsonObject with Volley
正在尝试从对象内部的行中获取值作为照片shows.but我在获取时遇到了一些问题。this is my json file
我正在尝试获取一些行,例如 "location" 或 "content"
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 Parsing Vollery Json Response
正在尝试从对象内部的行中获取值作为照片shows.but我在获取时遇到了一些问题。this is my json file
我正在尝试获取一些行,例如 "location" 或 "content"
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 Parsing Vollery Json Response