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