Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to parse in swift 2 #11

Open
speedoholic opened this issue Jul 26, 2016 · 0 comments
Open

Unable to parse in swift 2 #11

speedoholic opened this issue Jul 26, 2016 · 0 comments

Comments

@speedoholic
Copy link

I tried to parse this JSON using the following swift code but failed:

let jsonData = NSData(contentsOfFile: NSBundle.mainBundle().pathForResource("provinces", ofType: "json")!)
        if jsonData != nil {
            let json = try? NSJSONSerialization.JSONObjectWithData(jsonData!, options:NSJSONReadingOptions.AllowFragments)
            let array: Array<Dictionary<String, String>>? = json as? Array<Dictionary<String, String>>
            if array != nil {
                for dic in array! {
                     //never reaches here
                }
            } else {
                //always reaches here
                print("found nil array for province json")
            }

Since the same code is working for other JSON files, I assume there is some syntax error with respect to Swift.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant