我有以下代码,我正在尝试使用SwiftyJSON获取值:
let string =
"""
{"ResponseMetadata": {"RequestId": "b5d6ecad-e050-4d1f-8429-74a2775a6fe9", "HTTPStatusCode": 200, "HTTPHeaders": {"x-amzn-requestid": "b5d6ecad-e050-4d1f-8429-74a2775a6fe9", "content-type": "application/json", "content-length": "271", "date": "Tue, 22 Dec 2020 22:45:17 GMT"}, "RetryAttempts": 0}, "numberOfRecordsUpdated": 0, "records": [[{"stringValue": "6998DFFE-A9CF-4BEA-86AD-C356BB865E27"}, {"stringValue": "david.craine@yahoo.com"}, {"stringValue": "David"}, {"stringValue": "Craine"}, {"stringValue": "dcraine"}, {"stringValue": "vendor1"}, {"stringValue": "vendor1_werw8"}]]}
"""
let body = JSON(string)
print(">>>>>>>>> (body["records"])")
这将为body["records"]返回null。
我使用验证了此响应https://jsonformatter.curiousconcept.com/#,所以我假设它的格式是正确的。有人能帮忙吗?
尝试更改此行:
let body = JSON(string)
并调用以String
为参数的JSON
的init(parseJSON:)
初始化器,如下所示:
let body = JSON(parseJSON: string)