swiftyjson bundled file not parsing

107 views Asked by At

I've validated the coding and everything works up until I get to the actual parsing function I am unsure as to why I am not able to get any of the values in the array of the json file. I have tried multiple methods of getting every object in the array specified string and still nothing. This is the example code I have.

  [ { "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 }, ]
1

There are 1 answers

5
derdida On BEST ANSWER

If you use:

  json["array"].array 

Your JSON must look like:

{
  "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
    }
  ]
}

Because "array" is a key for an array.

Then you can use: (json is your JSON Array)

for obj in json["array"] {
    println(obj["Name"].stringValue)
}