0

http://www.google.com/dictionary/json?callback=dic&q=keyword&sl=en&tl=en&restrict=pr%2Cde&client=teからすべての値を抽出しようとしてい ます

GSONを使いたいのですが、どうすればいいのかわかりません。

すべての値を単純に抽出できる jericohtml パーサーに似たものはありますか?

また、Javaを使用する必要があります。jsonを取得できますが、定期的にフォーマットされていません(行ごとに書かれていることを意味します)

ありがとう

URL u=new URL(url);
     HttpURLConnection conn = (HttpURLConnection) u.openConnection();
     conn.setRequestMethod("GET");
     conn.setRequestProperty("Accept", "application/atom+xml");
     conn.setRequestProperty("User-Agent", "Mozilla/5.0 (Windows NT 5.2; rv:21.0) Gecko/20100101 Firefox/21.0");

    BufferedReader br=new BufferedReader(new InputStreamReader(conn.getInputStream()));
    String temp=br.readLine();
    String strJson=temp.substring("dic(".length(),temp.length()-",200,null)".length());

    System.out.println(strJson);
4

1 に答える 1

1

gson を使用して jsonobject を抽出し、ユーザー定義オブジェクトを設定できます。たとえば、ここをクリックして ください

Gson gson = new Gson();

    try {

        BufferedReader br = new BufferedReader(
            new FileReader("c:\\file.json"));

        //convert the json string back to object
        DataObject obj = gson.fromJson(br, DataObject.class);

        System.out.println(obj);

    } catch (IOException e) {
        e.printStackTrace();
    }
于 2013-06-27T11:50:16.257 に答える