1
options: [
"6GB RAM/128GB",
"8GB RAM/128GB",
"12GB RAM/256GB"
]

This JSON I want to parse using struct.

I have coded upto this :

struct Atts: Codable {
    let options: [Options]
    
    enum CodingKeys: String, CodingKey {
        case options
    }
}

struct Options: Codable {

}

But How to access the three elements in the "options" array?

Thanks in adv.

1
  • It's just an array of String, which conforms to Codable as is. Commented Oct 4, 2021 at 10:42

1 Answer 1

2

Replace

let options: [Options]

With

let options: [String]

And remove struct Options: Codable { Also using enum CodingKeys: String, CodingKey { is meaningless here as you don't change key name so remove it also , so all you need is

struct Atts: Codable {
   let options: [String]
}
Sign up to request clarification or add additional context in comments.

2 Comments

Hello, I'm having an issue in this case
How can this "options" be assigned to an array?.. Like I have done "var jsondata = [json]()" this previously!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.