私の Android アプリでは、Google Places URL からの JSON データを ListView に解析しようとしています。近くのレストランの名前をリストしようとしています。解析は機能しているように見えますが、JSON データから "name" 変数を取得する方法がわかりません。返されたリストには、次のような項目が含まれています。
{"id":
"6217c344be105e............"
{"id":
"2c66bf813799zr2844......"
私には、Google Place URL の「results」配列の「id」変数を解析しているように見えます。「結果」配列の「名前」変数を取得したい。誰かがこれを行うための正しいコードを教えてもらえますか? 私が使用しているJSON解析方法は次のとおりです。
public void parseJSON() throws ClientProtocolException, IOException, JSONException
{
String bcURL="https://maps.googleapis.com/maps/api/place/search/json?"
+ "location=" + latString + "," + longiString
+ "&radius=15000&"
+ "types=restaurant&sensor=false&key="
+ myPlaceKey;
//--- Get Places URL ----
client = new DefaultHttpClient();
HttpResponse response = client.execute(new HttpGet(bcURL));
int statusLine = response.getStatusLine().getStatusCode();
if(statusLine == 200){
HttpEntity e = response.getEntity();
String data = EntityUtils.toString(e);
JSONObject urlData = new JSONObject(data);
JSONArray resultsArr = urlData.getJSONArray("results");
int length = resultsArr.length();
List<String> listContents = new ArrayList<String>(length);
for (int i = 0; i < length; i++)
{
listContents.add(resultsArr.getString(i));
}
ListView restListView = (ListView) findViewById(R.id.jsonList);
restListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listContents));
}
//--- END Get Places URL ----
およびコードのリストビュー部分:
JSONArray resultsArr = urlData.getJSONArray("results");
int length = resultsArr.length();
List<String> listContents = new ArrayList<String>(length);
for (int i = 0; i < length; i++)
{
listContents.add(resultsArr.getString(i));
}
ListView restListView = (ListView) findViewById(R.id.jsonList);
restListView.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, listContents));
}
//--- END Get Places URL ----
コードの「名前変数を取得する」ビットはどこに行き、そのコードはどのようになりますか?