swiftyjson 捆绑文件不解析
swiftyjson bundled file not parsing
我已经验证了编码并且一切正常,直到我得到实际的解析函数我不确定为什么我无法获得 json 文件数组中的任何值.我已经尝试了多种方法来获取指定字符串数组中的每个对象,但仍然没有。这是我的示例代码。
[ { "Attack": 4, "Card Description": "<b>Deathrattle</b>Deal 2 damage to ALL other characters.", "Card Type": "0", "Class": "10", "Cost": 5, "Health": 4, "Name": "Abomination", "Rarity": 3 },
{ "Class": "1", "Name": "Fiery War Axe", "Cost": 2, "Card Type": 2, "Card Description": "", "Rarity": 5 }, ]
如果您使用:
json["array"].array
您的 JSON 必须如下所示:
{
"array": [
{
"Attack": 4,
"Card Description": "DeathrattleDeal 2 damage to ALL other characters.",
"Card Type": "0",
"Class": "10",
"Cost": 5,
"Health": 4,
"Name": "Abomination",
"Rarity": 3
},
{
"Class": "1",
"Name": "Fiery War Axe",
"Cost": 2,
"Card Type": 2,
"Card Description": "",
"Rarity": 5
}
]
}
因为"array"是数组的键。
然后你可以使用:(json是你的JSON数组)
for obj in json["array"] {
println(obj["Name"].stringValue)
}
我已经验证了编码并且一切正常,直到我得到实际的解析函数我不确定为什么我无法获得 json 文件数组中的任何值.我已经尝试了多种方法来获取指定字符串数组中的每个对象,但仍然没有。这是我的示例代码。
[ { "Attack": 4, "Card Description": "<b>Deathrattle</b>Deal 2 damage to ALL other characters.", "Card Type": "0", "Class": "10", "Cost": 5, "Health": 4, "Name": "Abomination", "Rarity": 3 },
{ "Class": "1", "Name": "Fiery War Axe", "Cost": 2, "Card Type": 2, "Card Description": "", "Rarity": 5 }, ]
如果您使用:
json["array"].array
您的 JSON 必须如下所示:
{
"array": [
{
"Attack": 4,
"Card Description": "DeathrattleDeal 2 damage to ALL other characters.",
"Card Type": "0",
"Class": "10",
"Cost": 5,
"Health": 4,
"Name": "Abomination",
"Rarity": 3
},
{
"Class": "1",
"Name": "Fiery War Axe",
"Cost": 2,
"Card Type": 2,
"Card Description": "",
"Rarity": 5
}
]
}
因为"array"是数组的键。
然后你可以使用:(json是你的JSON数组)
for obj in json["array"] {
println(obj["Name"].stringValue)
}