【发布时间】:2012-08-31 17:25:23
【问题描述】:
我是 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());
}
【问题讨论】:
-
如果我理解正确,因为它是一个数组,它可能包含多个电话号码。如果您确定只有一个电话号码,请尝试 0 index
标签: android json string parsing int