0

Hello friends I need your help for reading the array from the json object. like {"info":[{"memoID":"3","memoName":"Hello"}]} using SwiftyJSON

when I'm in android I can use JSONArray array = object.getJSONArray(“info”);

1
  • 1
    In Swift 4+ SwiftyJSON became obsolete. The Codable protocol is built-in (no dependencies!) and more efficient. Commented Jul 8, 2019 at 14:53

1 Answer 1

2

JSONDecoder

let content = try? JSONDecoder().decode(Root.self , from: data)
print(content)

// MARK: - Empty
struct Root: Codable {
    let info: [Info]
}

// MARK: - Info
struct Info: Codable {
    let memoID, memoName: String
}

SwiftyJson

if let res = arr["info"].array { // arr is of type JSON
  print(res)
}
Sign up to request clarification or add additional context in comments.

2 Comments

thanks but I want to use SwiftyJSON at sometime one class(ViewController.swift)
how you make the request Alamofire or what see edit

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.