0

I'm having problems parsing my JSON data to a Swift array (for use in a UITableView). Can anyone guide me?

My JSON data shows as:

[{"refID":"1","publisher":"Pub1"},{"refID":"2","publisher":"Pub2"},{"refID":"3","publisher":"Pub3"}] 

Any my Swift is:

override func viewDidLoad() {
    super.viewDidLoad()

    let url = NSURL(string: "http://myurl/index.php")
    var request = NSURLRequest(URL: url!)
    var data = NSURLConnection.sendSynchronousRequest(request, returningResponse: nil, error: nil)
    if data != nil {
        pubJSON = JSON(data: data!)
        println(pubJSON)            
    }

I can see the JSON in the output window so Xcode is reading it, but Im stumped as to the next step of converting it to an array.

Many thanks for any advice.

1 Answer 1

1

JSON parsing using NSJSONSerialization in iOS

Or check the documentation https://developer.apple.com/library/ios/documentation/Foundation/Reference/NSJSONSerialization_Class/

Sign up to request clarification or add additional context in comments.

Comments

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.