system21
system21

Reputation: 361

Pull json data into table view using swiftyJSON

How do I show the following code in table view using swift 2 swiftyJSON

I am new so full guide would be appreciated

I have already worked of other json open source projects but without swiftyJSON

  {"employees":[
    {"firstName":"John", "lastName":"Doe"},
    {"firstName":"Anna", "lastName":"Smith"},
    {"firstName":"Peter", "lastName":"Jones"}
]}

Upvotes: 0

Views: 131

Answers (1)

Peter
Peter

Reputation: 111

First of all, just read the SwiftJSON usage part, this is the right place to start.
Just some tips shortly:
First you need to get your json data from someone (in this case, this will come from a get request, and stored in NSData?)

  1. Store your json:
    let json = JSON(data: data!)
  2. Get the names from json and store it in var names = [String]()

let count = json["employees"].count for var i = 0; i < count; ++i { let name = json["employees"][i]["firstName"].stringValue self.names.append(name)
}


After that you should simple use this array in UITableView delegate methods.

Upvotes: 2

Related Questions