【发布时间】:2018-04-07 07:56:44
【问题描述】:
我想用 alamofire 和 swiftyjson 解析 JSON
我尝试像这样获取 JSON(值)
let headers: HTTPHeaders = [
"Authorization": "Basic Y2tfZTA1ZGNmMDkwNTNmODEyMGQwYTMyOGI4YzJkY2QzOTY5MmE5ZDAyNzpjc18zYzZiYWY2NTM0NDhkNDM4ZDM1ZDNmNDY5Nzg5ZGM2Y2VhZGRiZjNl",
"Accept": "application/json"
]
Alamofire.request("https://woo.demoapp.xyz/wp-json/wc/v2/products?category=15", headers: headers).responseJSON { response in
debugPrint(response)
if let json = response.result.value {
print("JSON: \(json)")
}
}
这是来自 woocommerce api 的 JSON 数据
[
{
"id": 29,
"name": "Sunglasses",
"permalink": "https://woo.demoapp.xyz/product/sunglasses/",
"description": "<p>Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas. Vestibulum tortor quam, feugiat vitae, ultricies eget, tempor sit amet, ante. Donec eu libero sit amet quam egestas semper. Aenean ultricies mi vitae est. Mauris placerat eleifend leo.</p>\n",
"images": [
{
"id": 17,
"src": "https://woo.demoapp.xyz/wp-content/uploads/2017/10/sunglasses.jpg",
"name": "Sunglasses",
}
],
问题是我无法用我认为正确的代码填充数组,以将带有 swiftyJSON 的 JSON 文件解析到 tableview。
【问题讨论】:
-
请搜索:There are many related questions并学习阅读JSON。这很简单:
{}是字典,[]是数组。所有的键都是字符串。双引号中的值为String,不带双引号的值为Int -
您想在表格视图中填充吗?还是简单?
-
我已经发布了答案,请使用此代码,我还测试了计数为 4。
-
@BHAVIKPANCHAL 我想填充表格视图。如何实施?
-
你能看到我发布的答案吗?
标签: swift3 alamofire swifty-json