我是 android 的菜鸟,我想用与此处示例相同的格式解析 google 响应 JSON: https ://developers.google.com/places/documentation/details 。我正在尝试获取字符串格式的电话号码。但是,当我从数组“事件”编码到 .getString 时,我的编辑器会要求一个 int 索引。我不明白发生了什么事。任何帮助是极大的赞赏。这是我的代码:
try {
JSONObject googleObject = StoresNearMe.getJSONfromURL(googleplacedetailapi);
JSONObject parsedGoogle = googleObject.getJSONObject("results");
JSONArray parsedevents = parsedGoogle.getJSONArray("events");
//thing.setText(googleplacesapi);
if(parsedevents.equals("") ){
Toast.makeText(FindDealer.this, "No nearby locations", Toast.LENGTH_LONG).show();
}else{
String phonenumber = parsedevents.getString("formatted_phone_number");
thing.setText(phonenumber);
}
} catch (JSONException e) {
Log.d("log_tag","JSON parsing error - Google Places Api:" + e.getMessage());
}