7

これらの種類の Json 応答を解析したい:

{
"MyResponse": {
    "count": 3,
    "listTsm": [{
        "id": "b90c6218-73c8-30bd-b532-5ccf435da766",
        "simpleid": 1,
        "name": "vignesh1"
    },
    {
        "id": "b90c6218-73c8-30bd-b532-5ccf435da766",
        "simpleid": 2,
        "name": "vignesh2"
    },
    {
        "id": "b90c6218-73c8-30bd-b532-5ccf435da766",
        "simpleid": 3,
        "name": "vignesh3"
    }]
 }
}

SIMPLE JSON パーサーを使用してみましたが、うまくいきません:

Object obj = parser.parse(resp);
JSONObject jsonObject = (JSONObject) obj;
JSONArray response = (JSONArray) jsonObject.get("MyResponse");

//JSONArray arr=new JSONArray(yourJSONresponse);
ArrayList<String> list = new ArrayList<String>();
for(int i=0; i<response.size(); i++){
    list.add(response.get(i)("name"));
}
4

2 に答える 2

-1

あなたは簡単に行うことができます:

JSONObject response = new JSONObject(resp);

次に、変数のタイプに応じて次のようなものを使用できます。

int count = response.getint("count");

また

JSONArray tsm = response.getJSONArray(listTsm)

次に、内部のオブジェクトを反復処理する場合は、 for だけを使用します。

于 2017-11-29T11:03:58.183 に答える