2017-11-14 10 views
0

id = 1のnameのすべての値をフィルタリングして配列に保存しようとしています。インデックスで配列をフィルタリングし、別の配列に保存する

これは私のWSから得られる出力です:

[{id = 1;名前=デモイン; }、{id = 2;名前=シーダーラピッズ; }、{id = 3;名前=ヤキマ; }、{id = 4;名前=フォートドッジ; }、{id = 1;名前=アイオワ市; }]

プロパティを取得しようとすると、コンテンツが分割されます。

希望の出力を得る方法を教えてもらえますか? JSONデータです

答えて

0

次のような何かを試すことができます jsonの文字列は次のようにする必要があります。

["items":{id = 1;名前=デモイン; }、{id = 2;名前=シーダーラピッズ; }、{id = 3;名前=ヤキマ; }、{id = 4;名前=フォートドッジ; }、{id = 1;名前=アイオワ市; }]

JSONObject jsonObject = null; 
jsonObject = new JSONObject("your json string goes here!!"); 
String items = jsonObject.getString("items"); 
JSONArray array = new JSONArray(weather); 
ArrayList<JSONObject > arrList = new ArrayList<JSONObject >(); 
for(int i = 0; i < array.length(); i++) 
{ 
    JSONObject jsonObject1 = array.getJSONObject(i); 
    arrList.add(jsonObject1); 
    String id = jsonObject1.get("id").toString(); 
    String name = jsonObject1.get("name").toString(); 

} 
関連する問題