【发布时间】:2018-05-01 13:00:30
【问题描述】:
这是我的 JSON - https://api.edamam.com/search?q=chicken。
我试图只获取作为食物名称的“标签”和作为食物照片的“图像”。
这是我下面的代码。
JsonObjectRequest(Request.Method.GET,url,null,new Response.Listener<JSONObject>()
{
@Override
public void onResponse( JSONObject response) {
try {;
JSONArray jsonArray = response.getJSONArray("hits");
for (int i = 0; i < jsonArray.length(); i++)
{
JSONObject jsonObject = jsonArray.getJSONObject(i);
String recipe = jsonObject.optString("recipe");
String name = jsonObject.optString("label");
String label = jsonObject.optString("image");
txtDisplay.setText(recipe + name + label);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Log.e("Volley", "Error");
}
});
queue.add(obreq);
}
}
此代码返回 JSON 数据,但它返回所有数据。
任何人都可以提供示例代码,以便它只返回特定的值。
谢谢
【问题讨论】:
标签: android json android-volley