我正在尝试使用NSJSONSeriallization.JSONObjectWithData
将NSData转换为JSON对象,我当前的代码是:
let response = try! NSJSONSerialization.JSONObjectWithData(receivedData, options: .MutableContainers) as! [String:AnyObject]
var receivedData
是1013个字节,包含来自API的JSON响应。
如果将我的NSData响应转换为使用此行代码而不是上一行的字符串:
let response = NSString (data: receivedData, encoding: NSUTF8StringEncoding)
使用Xcode调试我们可以看到response
作为字符串是:
这是一个更清晰的JSON字符串视图:
{
"id": "373198",
"result": {
"registrationId": 742098068,
"imageUrl": "/templates/images/user.gif",
"external": false,
"clientCode": "",
"settings": null,
"firstLogin": false,
"type": null,
"fromSite": null,
"city": "",
"sessionToken": "1457206061819919",
"username": "buffettidemo",
"postalCode": null,
"phoneNumber": "",
"permissions": null,
"role": null,
"gender": "",
"specialBonus": null,
"verifyPhone": null,
"autocashout": null,
"wizardFlags": 1,
"lastName": "Demo",
"enableMail": true,
"extType": null,
"companyName": null,
"extId": null,
"country": "",
"paypalAccountEmail": null,
"console": 2,
"authorizationProfile": null,
"thumbnail": null,
"email": "adriano.tamburo@gmail.com21",
"javaClass": "guardian.dto.UserAdaptor",
"language": null,
"numInvitation": 0,
"region": null,
"enablePhone": true,
"registerDate": "1426693995000",
"verifyMail": null,
"id": 80447,
"firstName": "Buffetti",
"salesFee": null,
"website": null,
"dateBirth": "1426693995000",
"taxCode": null,
"quotesOrders": null,
"permissionApp": null,
"address": null,
"authorizationExpired": false,
"vatNumber": null,
"mobileNumber": null
}
}
我的问题是,回到使用这行代码:
let response = try! NSJSONSerialization.JSONObjectWithData(receivedData, options: .MutableContainers) as! [String:AnyObject]
我的词典对象[string:AnyObject]
没有条目: