-2
JSONレスポンスを返す以下のURIがあります。
getリクエストの応答と、steps
配列へのアクセスを解析しようとしましたが、最初の手順で停止します。ここでJSON RESTレスポンスを解析する方法 - NoClassDefFoundError:org/json/JSONArray
私のコードです:
public void getRoute() throws Exception {
String urlToRead="https://maps.googleapis.com/maps/api/directions/json?origin=41.43206,-81.38992&destination=Montreal&key=XXX";
DefaultHttpClient httpClient = new DefaultHttpClient();
HttpGet getRequest = new HttpGet(urlToRead);
getRequest.addHeader("accept", "application/json");
HttpResponse response = httpClient.execute(getRequest);
String json = IOUtils.toString(response.getEntity().getContent());
JSONArray array = new JSONArray(json);
for (int i = 0; i < array.length(); i++) {
JSONObject object = array.getJSONObject(i);
System.out.println(object.getJSONArray("routes"));
}
}
が、それはして文句を言う:
Exception in thread "main" java.lang.NoClassDefFoundError: org/json/JSONArray
Mavenのは、次のとおりです。
<groupId>com.googlecode.json-simple</groupId>
<artifactId>json-simple</artifactId>
<version>1.1.1</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.1.1</version>
</dependency>
で
を交換してはいるようだ – Arvind
エラーは単にあなたが実行時の依存関係が欠落していると言います。クラスパスに 'json.jar'を追加する必要があります –