0
我想分析这个链接的JSON文件:http://maps.googleapis.com/maps/api/directions/json?origin=33.7489,-84.3881&destination=33.7514,-84.7478&sensor=false为什么不能让我分析JSON?
我想解析“html_instructions”字符串,从“步骤”数组作为这样的:
String googledirectionsapi = "http://maps.googleapis.com/maps/api/directions/json?origin=" + origin + "&destination=" + destination0 + "&sensor=false";
try {
JSONObject googleObject = Directions.getJSONfromURL(googledirectionsapi);
JSONArray parsedGoogleDirections = googleObject.getJSONArray("routes").getJSONArray("steps");
thing.setText(googledirectionsapi);
if(parsedGoogleDirections.equals("")){
Toast.makeText(FindDealer.this, "Cannot find suitable route", Toast.LENGTH_LONG).show();
}else{
for (int i = 0; i < parsedGoogleDirections.length(); i++) {
JSONObject instructions = parsedGoogleDirections.getJSONObject(i);
if (i == 0){
String step1 = parsedGoogleDirections.getString("html_instructions");
}
}
}
}catch (JSONException e) {
Log.d("log_tag","JSON parsing error - Google Directions Api:" + e.getMessage());
}
但是,日食是给我在错误:
.getJSONArray("steps"); //<-- The method getJSONArray(int) in the type JSONArray is not applicable for the arguments (String).
和,也给我的错误在:
.getString("html_instructions"); //<--he method getString(int) in the type JSONArray is not applicable for the arguments (String)
为什么eclipse会显示这些错误?我以前从未遇到过这个问题。先谢谢你。
非常感谢你缪拉。 – 2012-08-07 01:56:11