0

I have the following json output. How to parse json in swift so that I can display it in table view?

[{"firstName":"faisal","address":"Apartemen Casa Grande 0708"}]
Rumin
  • 3,787
  • 3
  • 27
  • 30
Faisal
  • 308
  • 4
  • 19

1 Answers1

1

Try this code i hope help you

  var parseError: NSError?
  let parsedObject: AnyObject? = NSJSONSerialization.JSONObjectWithData(data,
    options: NSJSONReadingOptions.AllowFragments,
    error:&parseError)
 
  //2
  if let topApps = parsedObject as? NSArray 
  {
    if let feed = topApps["firstName"] as? NSDictionary 
    {
      if let feed = topApps["address"] as? NSDictionary 
      {
           println("Optional Binding: \(appName)")
      }
    }
 }
Nikunj
  • 655
  • 3
  • 13
  • 25
  • I will implement and test this code, thank you :) – Faisal Oct 20 '15 at 05:15
  • if this code is work for you then Accept and upvote my answer @Faisal Thanks.. – Nikunj Oct 20 '15 at 05:17
  • is this swift 1? Extra argument 'error' in call and i read about this http://stackoverflow.com/questions/31073497/swift-extra-argument-error-in-call this show me a different code for Swift 2, can you help me solve this? thank you @Nikunj :) – Faisal Oct 20 '15 at 08:14
  • this is swift 1.2 @Faisal – Nikunj Oct 20 '15 at 08:49
  • my requirement is swift 2 @Nikunj :D – Faisal Oct 20 '15 at 09:10
  • thank you @Nikunj i just found the answer in this link http://stackoverflow.com/questions/31858531/swift-2-loop-through-json-array – Faisal Oct 20 '15 at 12:06