2012-04-19 3 views
0

나는 이미 가지고있는 배열로부터 새로운 JSONArray를 생성 할 수 있어야합니다. id라는 필드 전체가 각 행마다 다른데, 어떻게 그리스트를 얻을 수 있습니까?JSONArray가 결과에서 다른 배열을 나열합니까?

예 : 나는 이걸 돌려 받았다.

[{"id":111,"users":"blob"}, 
{"id":111,"users":"blob"}, 
{"id":111,"users":"blob"}, 
{"id":111,"users":"blob"}, 
{"id":111,"users":"blob"}, 
{"id":111,"users":"blob"}] 

ID의 목록은 어떻게 얻을 수 있습니까?


  • 편집

똑바로 감사하지만,이 후 루프를 사용하기로 결정 :

HttpResponse response = httpclient.execute(httpget); //execute the HttpPost request 
JSONArray jsa = projectResponse(response); //get the json response 

for(int i = 0; i < jsa.length(); i++){ 
    JSONObject jso = jsa.getJSONObject(i); 
    publishProgress(jso.getString("id"), jso.getString("name")); 
} 
+0

를 시도? –

+0

이 게시물을 참조하십시오. 이것은 당신을 도울 것입니다. http://stackoverflow.com/questions/2487841/jquery-parse-json-multidimensional-array – Akilan

답변

1

이 밖으로 시도 D :

다음
JSONArray yourJSONArray; 
List<String> tempIDStringCollection = new List<String>(); 
... 

for(int i = 0; i < yourJSONArray.length(); i++){ 
     String id = yourJSONArray.getJSONObject(i).getString("id"); 
     tempIDStringCollection.add(id); 
} 

하는 전송 이것을 다른 것으로 JSONArray, 시도 :

JSONArray newArray = new JSONArray(tempIDStringCollection); 

List 생성을 건너 뛰려면, 잘못된 루프 for``유행 좋은 '팔자로 새로운`JSONArray`를 구축 무슨

JSONArray yourJSONArray; 
JSONArray newArray = new JSONArray(); 
... 

for(int i = 0; i < yourJSONArray.length(); i++){ 
     String id = yourJSONArray.getJSONObject(i).getString("id"); 
     newArray.put(i, id); 
} 
관련 문제