2013-04-10 4 views
3

나는 페이스 북과 통합 된 안드로이드 애플 리케이션에서 일하고있다. 나는 페이스 북에서 정보를 가져 오기 위해 fql 쿼리를 사용하고있다. 내 fql 메서드는Json 객체에서 데이터를 가져 오는 방법은 무엇입니까?

   void runfql(){ 
       String fqlQuery = "SELECT uid, name, pic_small,birthday FROM user WHERE uid IN " + 
        "(SELECT uid2 FROM friend WHERE uid1 = me())"; 
       Bundle params = new Bundle(); 
       params.putString("q", fqlQuery); 
       Session session = Session.getActiveSession(); 
       Request request = new Request(session, 
       "/fql",       
       params,       
       HttpMethod.GET,     
       new Request.Callback(){   
         public void onCompleted(Response response) { 

         JSONObject myjson=response.getGraphObject().getInnerJSONObject(); 
         Log.d("ResultResultResult: " ,""+myjson);       
         }     
        }); 
        Request.executeBatchAsync(request); 

       } 

myjson 개체가 내가 원하는 정보입니다. 이렇게

{"data":[{"uid":536089174,"birthday":"July 22","name":"Usman Aslam Sheikh"},{"uid":581379174,"birthday":"July 26","name":"Ammar Khalid"} 

질문은 다른 배열에 정보를 저장하는 방법은 무엇입니까 ??

이 목적을 위해 올바른 코드를 입력하십시오. 당신이 된 JSONObject 및 JSONArray이 같은 코드가 ...이 ... 당신에게 도움이 될 수 있습니다

+0

가나요? 또는 GSON 어쩌면? – BobTheBuilder

답변

9
String jsonString = yourstring; 
JSONObject jsonResult = new JSONObject(jsonString); 
JSONArray data = jsonResult.getJSONArray("data"); 
if(data != null) { 
    String[] names = new String[data.length()]; 
    String[] birthdays = new String[data.length()]; 
    for(int i = 0 ; i < data.length() ; i++) { 
     birthdays[i] = data.getString("birthday"); 
     names[i] = data.getString("name"); 
    } 
} 

체크 http://www.androidhive.info/2012/01/android-json-parsing-tutorial/

+0

이런 종류의 객체는 무엇입니까? ''{ "id": "1019", "level": "1", "time_in_secs": "3", "par": "0", "initials": "EGB", "quote": " "time_stamp": "2014-01-26 11:20:20"}, { "id": "1018", "level": "1", "time_in_secs": "3", " 파 ":"0 ","이니셜 ":"EGB ","따옴표 ":"방금 소녀가 이겼어! ","time_stamp ":"2014-01-26 11:19:24 "}, {" "0", "0", "quote": "패자", "time_in_secs": "3" ":"2014-07-10 09:11:55 "}]' –

+0

String jsonString = yourstring; JSONObject jsonResult = 새 JSONObject (jsonString); JSONArray data = jsonResult.getJSONArray (""); if (data! = null) { String [] names = new String [data.length()]; String [] birthdays = new String [data.length()]; for (int i = 0; i

0

편집을 볼

JSONObject resultObject = new JSONObject(response); 

JSONArray JArray = resultObject.getJSONArray("data"); 

       for (int t=0; t<JArray.length(); t++) { 

        JSONObject JObject = JtArray.getJSONObject(t); 



builder.append(JObject.getString("uid")+": "); 
관련 문제