【发布时间】:2020-10-31 03:38:58
【问题描述】:
我从原始 JSON 字符串创建了一个 JSONObject。然后我从它创建了一个JSONArray。我正在尝试访问JSONArray 的每个索引的"location" 列表,因为我需要"location" 构造函数的"location" 信息。
这是我目前所拥有的
try
{
//create a JSON Object with the raw string
JSONObject json=new JSONObject(responseData);
//create array of businesses
JSONArray arr=json.getJSONArray("businesses");
for(int i=0;i<arr.length();i++)
{
//I need "location" info here
locations.add(new Location(arr.getJSONObject(i).getString("id"),arr.getJSONObject(i).getString("name"), arr.getJSONObject(i).getString("image_url"),"placeholder",0));
}
}
catch (JSONException e)
{
e.printStackTrace();
}
【问题讨论】:
标签: java json android-studio