2017-04-14 25 views
-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> 
+1

<groupId>com.googlecode.json-simple</groupId> <artifactId>json-simple</artifactId> <version>1.1.1</version> 

を交換してはいるようだ – Arvind

+1

エラーは単にあなたが実行時の依存関係が欠落していると言います。クラスパスに 'json.jar'を追加する必要があります –

答えて

0

org/json/JSONArray

あなたは間違ったライブラリをコンパイルおよび/または間違ったクラスをインポートしました。あなたがクラスパスにjarファイルを逃しているよう

<groupId>org.json</groupId> 
<artifactId>json</artifactId> 
<version>20160810</version> 
関連する問題