2017-07-15 18 views
0

我的JSON格式:如何使用Parse Server API格式在iOS中存儲和訪問JSON?

{ 
    "results": [ 
     { 
      "objectId": "1a8SJaCo2P", 
      "Name": "Banyan Tree", 
      "Amount": 300, 
      "Area": "Nizampura", 
      "Cuisins": [ 
       "Asian", 
       "Italian", 
       "Chaat", 
       "Awadhi" 
      ], 
      "Facility": [ 
       "Music", 
       "Smoking Area", 
       "Take Away", 
       "Home Delivery" 
      ], 
      "Restaurant_Images": { 
       "__type": "File", 
       "name": "a138194bc773ffa570a27a640d66f89f_5.jpg", 
      } 
     }, 
    ] 
} 

我知道如何解析基本JSON格式,但它有一個{ 「成果」:[{USER1},{}用戶2,...]}的數據。那麼如何解析它呢?

這是back4app(parse.com)API請求的格式

+0

你能告訴我你的雲代碼功能嗎 –

回答

1

我不知道,如果你正在序列化的數據或RAWDATA。但我會假設你正在獲取rawData。所以,你可以試試以下內容

let serializedJson = try JSONSerialization.jsonObject(with: responseData, options: .mutableContainers) 
    if let expectedResults = serializedJson as? [String:Any] { 
     if let users = expectedResults["results"] as? [Any] { 
      for user in users { 
       //you will get the values 
       // now if it is parseable to PFUser 
       //Then you can have 
       if let user = user as? PFUser { 
        //you will have individual user 
       } 
       //If not parseable to PFUSer then you can parse it manually 
      } 
     } 
    } 
相關問題