jaykaydev
jaykaydev

Reputation: 141

Parse a JSON with swiftyJson

I'm using SwiftyJson and I wrote the code below,

for (_, value) in json["assets"] {
   print(value)
}

I got this result in my console what is I expect:

[
  {
    "urlImage" : "https:myFirstUrl",
    "page" : 1
  },
  {
    "urlImage" : "https:mySecondUrl",
    "page" : 2
  }]

But now I want to retrieve "urlImage" to assign this value in a constant.

Upvotes: 0

Views: 61

Answers (1)

Rafaela Lourenço
Rafaela Lourenço

Reputation: 1166

You can try this:

    for (_, value) in json["assets"] {
        for item in value.arrayValue {
            let url = item["urlImage"].stringValue
            print(url)
        }
    }

I hope it helps.

Upvotes: 2

Related Questions