我想获得JSON Array
,看起来像这样
[
{
"number": "111-1001"
},
{
"number": "111-1002"
},
{
"number": "111-1003"
}
]
为了解析这个,我写下这段代码:
let registeredNumberUrl = "http://myURL"
let url = URL(string: registeredNumberUrl)
do {
let allregisteredNumber = try Data(contentsOf: url!)
let jsonResult = try JSONSerialization.jsonObject(with: allregisteredNumber , options: []) as? [[String:Any]]
print("jsonResult \(jsonResult?.count)")
} catch let error as NSError{
print(" !!!! registered was not succeded !!!! \(error)")
}
}
但是我收到了这个错误:
Error Domain=NSCocoaErrorDomain
Code=3840
"No value for key in object around character 41."
UserInfo={NSDebugDescription= No value for key in object around character 41.
}
我尝试过这样的解决方案 SWIFT 2: Loop through JSON array 但我一直得到同样的错误: