2016-11-17 15 views
-1

これは、atributeの名前と値をfromstring jsonデータから取得するためのコードです。コードはerrrorなしで実行されていますが、結果はnullです。このすべての上記のあなたの輸入コードでJavaを使用してJSONデータを呼び出す

import java.io.*; 
import java.net.*; 

import org.json.simple.JSONArray; 
import org.json.simple.JSONObject; 
import org.json.simple.parser.JSONParser; 
import org.json.simple.parser.ParseException; 

    public class A18 { 
public static void main(String[] args) throws ParseException{ 
String[] out2; 
String out,out1= null; 
try{ 
    URL a=new URL("URL"); 
    HttpURLConnection b=(HttpURLConnection) a.openConnection(); 
    b.setRequestMethod("GET"); 
    b.setRequestProperty("Accept", "application/json"); 
    BufferedReader c=new BufferedReader(new InputStreamReader(b.getInputStream())); 
    StringBuilder sb=new StringBuilder(); 



while((out=c.readLine())!=null) 
{ 
    sb.append(out); 
out1=sb.toString(); 
} 

c.close(); 
b.disconnect(); 


JSONObject obj = new JSONObject(); 
    String id = obj.toJSONString("collection"); 
    String error = obj.toJSONString("links"); 
} 
     catch (Exception e) 
    { 

     e.printStackTrace(); 
     return; 
    } 

    }} 
+2

重要性が高いと思われるインポートステートメントを表示してください。 – Seelenvirtuose

+2

インポートを確認してください。 2つのJSON解析ライブラリを一緒に使用していて、間違ったJSONObjectをインポートしたようです。 – RealSkeptic

+0

私はそのおかげで解決しましたが、別のエラーが発生しています – codehacker

答えて

-1

あなたはimport org.json.simple.JSONObjectに役立つべきであると変更、import org.json.JSONObjectを抱えています。

org.json.xのインポートが他にもあります。org.json.simple.xに変更する必要があります。

関連する問題