【发布时间】:2017-07-17 06:38:17
【问题描述】:
{
"status": true,
"status_code": 1,
"content": [
{
"cat_id": "3",
"cat_name": "Food",
"cat_parentid": "2"
},
{
"cat_id": "4",
"cat_name": "Entertainment",
"cat_parentid": "2"
},
{
"cat_id": "5",
"cat_name": "Cars",
"cat_parentid": "2"
},
{
"cat_id": "12",
"cat_name": "Personal Care",
"cat_parentid": "2"
}
],
"message": "Success"
}
更新
do {
//create json object from data
if let json = try JSONSerialization.jsonObject(with: data, options: .mutableContainers) as? [String: Any] {
completion((json as? AnyObject)!) //here completion callback will return the jsonObject to my UIViewController.
}
} catch let error {
print(error.localizedDescription)
}
这是我的 JSONObject。我对斯威夫特很陌生。如何快速获取内容 JSONArray 和进一步处理。?任何人都可以帮助我吗?帮助将不胜感激。
【问题讨论】:
-
你序列化了吗?
-
在 iOS 中,您可以使用序列化将您的 JSON 转换为字典,然后解析您的数据
-
是的。我把它序列化了。我更新了我的问题。你现在可以检查了。
-
让 number = result?.object(forKey: "status") as! Bool if number == true { let dataArr = result?.object(forKey: "content") as! NSArray }