2012-11-10 7 views
1

내가 JSON 배열에 접근하고 있음에 구문 분석 JSON과 하나의 작은 응용 프로그램을 만들 수 있지만,이 jsonarray에 내가 PHONENUMBERS 제목과 addressline하지만 전화 번호를 ican't에 액세스하는 방법을 이렇게 이해에 액세스하는 방법을동일한 객체 배열 내의 배열 내에 json 배열이 있습니까?

여기

은 JSON이 원하는 포맷

> { 
    "responseData": { 
     "results": [ 
      { 
       "title": "Pakvan Dining Hall", 
       "phoneNumbers": [ 
        { 
         "type": "", 
         "number": "079 26636473" 
        }, 
        { 
         "type": "Mobile", 
         "number": "09427608429" 
        } 
       ], 
       "addressLines": [ 
        "Vadilal Sarabhai Hospital", 
        "Ahmedabad, Gujarat 380006, India" 
       ] 
      }, 
      { 
       "title": " Dining Hall", 
       "phoneNumbers": [ 
        { 
         "type": "", 
         "number": "079 26645473" 
        }, 
        { 
         "type": "Mobile", 
         "number": "09427608429" 
        }, 
        { 
         "type": "", 
         "number": "079 26645473" 
        }, 
        { 
         "type": "Mobile", 
         "number": "09427608429" 
        } 
       ], 
       "addressLines": [ 
        " Sarabhai Hospital", 
        "Ahmedabad, Gujarat 380006, India" 
       ] 
      }, 
} 

의 ArrayList> contactList = 새로운 ArrayList를>();

JsonParser jparser= new JsonParser(); 
    String jsonstringfunction =jparser.jsonstringfunction(url); 

    Log.e("Jsonstringfunction","n"+jsonstringfunction); 

    try 
    { 
     JSONObject jsonObject2 = new JSONObject(jsonstringfunction); 

     JSONObject response = jsonObject2.getJSONObject(TAG_RESPONSE); 
     JSONArray jresults=response.getJSONArray(TAG_RESULTS); 
     Log.e("check","3333"+jresults); 

     for (int i = 0; i < jresults.length(); i++) 
     { 
      Log.e("check","4444"+jresults.length()); 
      String titlenoformating = jresults.getJSONObject(i).get(TAG_TITLENOFORMATING).toString(); 

      Log.e("Title",""+titlenoformating); 

      HashMap<String, String> map = new HashMap<String, String>(); 
      map.put(TAG_TITLENOFORMATING,titlenoformating); 

      JSONArray jaddressline=jresults.getJSONObject(i).getJSONArray(TAG_ADDRESSLINES); 

      Log.e("addressline","addressline"+jaddressline); 
      String addressline2=""; 
      for(int j=0;j<jaddressline.length();j++) 
      { 
       addressline2=addressline2+jaddressline.getString(j).toString(); 

       Log.e("addressline","jaddressline"+addressline2); 
      } 
      // adding each child node to HashMap key => value 
      map.put(TAG_ADDRESSLINES,addressline2); 

      JSONArray jphonenumbers=jresults.getJSONObject(i).getJSONArray(TAG_PHONENUMBERS); 

      for(int k=0;k<jphonenumbers.length();k++) 
      { 

       Log.e("Phonenumbers","phonenumbers"+jphonenumbers); 

      JSONArray jtype=jphonenumbers.getJSONObject(k).getJSONArray(TAG_TYPE); 

       Log.e("JsonPhone","type"+jtype); 
       for(int m=0;m<jtype.length();m++) 
       {     

        String type=jtype.getString(m).toString(); 

        Log.e("type","type"+type); 
       }  

      } 


      contactList.add(map); 
     } 
+0

내가 다른 알고하지만 난 돈; t 난 이제 솔루션을 가지고 samae 객체 – user1611222

+0

로 withinarray PHONENUMBER 배열에 접근하는 방법을 이해 – user1611222

+0

그런 다음 닫거나 솔루션을 올려주십시오.) – Warpzit

답변

1
String[] title,number,address; 
JSONObject jobject = new JSONObject(your_result_object); 
JSONObject json=jobject; 
JSONObject jresponse = json.getJSONObject("responseData"); 
JSONArray jresult = jresponse.getJSONArray("results"); 

title = new String[jresult.length()]; 

for(int i=0;i<jresult.length();i++){ 
JSONObject obj = jresult.getJSONObject(i); 
title[i] = obj.getString("title"); 

JSONArray jphonenumbers = obj.getJSONArray("phoneNumbers"); 
number = new String[jphonenumbers.length()]; 

for(int j=0;j<jphonenumbers.length();j++){ 
JSONObject obj2 = jphonenumbers.getJSONObject(j); 
number[j] = obj2.getString("number"); 
} 

JSONArray jaddress = obj.getJSONArray("addressLines"); 
address = new String[jaddress.length()]; 
for(int k=0;k<jaddress.length();k++){ 
address[k] = jaddress.getString(k); 
} 
} 
0

전화 번호 배열은 여기에 액세스 할 수 있어야합니다 :

responseData.results['phonenumber']