2016-12-02 5 views
0

私はAPIから受け取ったJSONデータからデータを抽出します。
私はJsonarrayから単純なjsonArrayデータまたはJsonObjectを取得する方法を知っていますが、私はJSONのネストを初めてお勧めします。別のJsonObject間でJsonObjectを抽出します

このデータはどのように抽出できますか?

{ 
    "call_log": { 
     "7837369400": { 
      "7000011216180827872": { 
       "start_date": "01 Dec 2014", 
       "start_time": "06:08 PM", 
       "end_date": "01 Dec 2014", 
       "end_time": "06:10 PM", 
       "call_sdate": "2014-12-01 18:08:27.000", 
       "call_edate": "2014-12-01 18:10:03.000", 
       "call_type": "1", 
       "caller": "0000000000", 
       "duartion": "94", 
       "call_duartion": "01:34", 
       "dtmf": "NA", 
       "dt_number": "0000000000", 
       "recording_path": "28.wav", 
       "agent_mobile": "0000000000", 
       "agent_name": "something" 
      }, 
      "7000301116163015079": { 
       "start_date": "30 Nov 2014", 
       "start_time": "04:30 PM", 
       "end_date": "30 Nov 2014", 
       "end_time": "04:31 PM", 
       "call_sdate": "2014-11-30 16:30:15.000", 
       "call_edate": "2014-11-30 16:31:14.000", 
       "call_type": "1", 
       "caller": "0000000000", 
       "duartion": "59", 
       "call_duartion": "00:59", 
       "dtmf": "NA", 
       "dt_number": "0000000000", 
       "recording_path": "30.wav", 
       "agent_mobile": "0000000000", 
       "agent_name": "something" 
      } 
     } 
    } 
} 

私がしようとしているコードは次のとおりです。

try { 
    JSONObject jObject= new JSONObject(response).getJSONObject("call_log"); 
    Iterator<String> keys = jObject.keys(); 
    while(keys.hasNext()) 
    { 
     String key = keys.next(); 
     // __________________________ 

     // __________________________ 
     Log.v("**********", "**********"); 
     Log.v("category key", key); 


     // JSONObject jO= new JSONObject(response).getJSONObject(key); 
     // Log.v("next is", jO.toString()); 
     // JSONObject innerJObject = jObject.getJSONObject(key); 

     // String name = innerJObject.getString("start_date"); 
     // String term_id = innerJObject.getString("start_time"); 

     //Log.v("name = "+name, "term_id = "+term_id); 

    } 
} 
catch (JSONException e){ 
    e.printStackTrace(); 
} 

答えて

1

私はJSONが正しく...

1)はコールログ
2を取得することを読めば)番号を取得します
3)その番号のエントリを取得
4)そのエントリから値を取得

JSONObject responseObject = new JSONObject(response); 
JSONObject callLog = responseObject.getJSONObject("call_log"); // 1 

Iterator<String> phoneNumbers = callLog.keys(); // 2 

while(phoneNumbers.hasNext()) { 
    JSONObject numberLog = callLog.getJSONObject(phoneNumbers.next()); 
    Iterator<String> callEntries = numberLog.keys(); // 3 

    while(callEntries.hasNext()) { 
     JSONObject entry = numberLog.getJSONObject(callEntries.next()); 

     // 4 
     String name = entry.getString("start_date"); 
+0

okk今私は私の質問を訂正し、私はデータを取得するために行を取得するためにurコードを使用していますJSONObject entryObject = numberLog.get(entry);その通りです。必要なorg.json.JSONObjectが見つかりました。java.lang.Object ... @ cricket_007 –

+0

'getJSONObject' –

+0

ああああああ@ cricket_007ありがとう –