Swift:如何为组成员解析JSON Facebook图形数据

时间:2015-11-12 06:10:31

标签: json swift

如何将此JSON解析为字典数组 - [String:AnyObject]?

typealias FBUser = [String: AnyObject]
var fbGroup = [FBUser]()

func logUserGroup() {
    let graphRequest = FBSDKGraphRequest(graphPath: "88##########6270/members", parameters: ["fields": "id, name"], HTTPMethod: "GET")
    graphRequest.startWithCompletionHandler { (connection, result, error) -> Void in
        if error != nil {
            print(error)
        } else {
            if let resultdict = result as? [NSDictionary] {

                for member in resultdict {
                    var user = FBUser()
                    if let idvalue = member["id"] as? String {
                        user["id"] = idvalue
                    }
                    if let name = member["name"] as? String {
                        user["name"] = name
                    }
                    self.fbGroup.append(user)
                }
            }
        }
    }
}

Facebook JSON:

{
  data =  (
            {
        id = 102055#####10000;
        name = "Kristian";
    },
            {
        id = 10208######08475;
        name = "Oren";
    },
            {
        id = 1020#######57409;
        name = "Ron";
    }
  };
}

如果有一个很好的资源可以提供非常有用的不同解析技术。

0 个答案:

没有答案