-1

サーバーでツリー情報を JSON 形式で返すクエリを実行しています。下

[{"leaf": 0, "context": {}, "text": "ABC-1-6-1", "expandable": 1, "id": "1.1.2.202.ABC-1-6-1", "allowChildren": 1}]

私はjson-simpleライブラリで遊んでいましたが、上記の情報を文字列形式で取得できる場合、JSONParserを使用して問題なく解析できます。

String jsonString = "{\"leaf\": 0, \"context\": {}, \"text\": \"1.1.2.202.ABC-1-6-1\", \"expandable\": 1, \"id\": \"1.1.2.202.ABC-1-6-1\", \"allowChildren\": 1}";

どんな助けでも素晴らしいでしょう!

4

2 に答える 2

0

JSON を Java に変換する場合は、gson を使用します。それはとても簡単です。

  Person fromJson = new Gson().fromJson(json, Person.class);// this will convert json to java object
        fromJson.setAge(15);
        fromJson.setName("json");
        fromJson.setEmail("email@gmail.com");
        fromJson.setMob("4657576876");

        json = new Gson().toJson(fromJson);// this will convert java to json string like this {"name":"json","age":15,"email":"email@gmail.com","mob":"4657576876"}

https://sites.google.com/site/gson/gson-user-guide

json配列変換については以下のリンクを参照

json 配列のシリアライズとデシリアライズ

于 2013-02-11T12:08:21.280 に答える
0

Java用の多くのJSONパーサーがあります

于 2013-02-11T12:13:21.447 に答える