2017-10-18 13 views
0

で辞書にJSONに変換するためにどのように私はRESTはFirebaseサーバーと 応答はJSONオブジェクトであるに蒸気を実行している私自身のサーバーからの呼び出しを行います。
"1508321173"の下の要素を実際の値を知らなくてもどのように取得できますか?これはタイムスタンプを表します。したがって、この値は常にデータベース内では動的です。はスウィフト3蒸気

let jsonObject:JSON = [ 
"EmailAddress": "[email protected]", 
"PhoneNumber": 07672395038, 
"RescheduledByCustomer": 
    [1508321173: 
     ["BookingStatusClient": "true", 
     "DateAndTime": "Fri, 20 Oct 2017 18:30"] 
    ], 
"BookingNumber":"726070304" 
    . 
    . 
    . 
] 



let jsonObject:JSON? 

if let arrayOfDict:Any = jsonObject?.object?["RescheduledByCustomer"]{ 
       print("arrayOfDict is \(arrayOfDict)") 

プリント:Node.Node.object([ "1508321173": Node.Node.object([ "BookingStatusClient":Node.Node.string( "真" arrayOfDictは、JSON(ノードであります)、
"のDateAndTime":Node.Node.string( "金、2017年10月20日18時30")])]))

if let underTimeStamp = arrayOfDict as? [[String: Any]]{ 
     print("underTstamp is \(underTstamp)") 
      //it does not print anything 
    //how can I get the elements under "1508321173" ? 
       }   
    } 

答えて

0
//get the object under timeStamp 1508321173 


let arrayOfTimeStamps = jsonObject?["RescheduledByCustomer"]?.object?.keys 
    for timeStampKey in arrayOfTimeStamps?.array ?? [] { 
    let dictUnderTstamp = jsonObject?["RescheduledByCustomer"]?.object?[timeStampKey] 


      for i in (dictUnderTstamp?.object)!{ 
       print("i key dictUnderTstamp is \(i.key)") 
       print("i value dictUnderTstamp is \(i.value)") 
      } 
     } 
関連する問題