-1

I have a problem with JSON file parsing how correctly parse it? I'm new for Swift and try parse JSO but got empty. Actually list is not empty, Debugger Image :

debugger show The issue is how can I parse json
JSON:

 {
    "list" : { 
    "meta" : { 
    "type" : "resource-list",
    "start" : 0,
    "count" : 188
    },
    "resources" : [ 
    {
    "resource" : { 
    "classname" : "Quote",
    "fields" : { 
    "name" : "USD/KRW",
    "price" : "1147.310059",
    "symbol" : "KRW=X",
    "ts" : "1489185046",
    "type" : "currency",
    "utctime" : "2017-03-10T22:30:46+0000",
    "volume" : "0"
    }
    }
    }
    ,
    {
    "resource" : { 
    "classname" : "Quote",
    "fields" : { 
    "name" : "SILVER 1 OZ 999 NY",
    "price" : "0.058634",
    "symbol" : "XAG=X",
    "ts" : "1489325701",
    "type" : "currency",
    "utctime" : "2017-03-12T13:35:01+0000",
    "volume" : "36"
    }
    }
    }

Swift Code:

    let Url = NSURL(string: stockUrl)
    let request = NSMutableURLRequest(url: Url! as URL)

    let task = URLSession.shared.dataTask(with: request as URLRequest){ data, response, error in

        if error != nil
        {
            print("error=\(error)")
            return
        }


do {
     if let data = try JSONSerialization.jsonObject(with: data!, options: []) as?  [String: AnyObject]{

       let list = data["list"] as? [[String: Any]] ?? []
       print(list)

        }
        } catch let error as NSError {
            print(error.localizedDescription)
        }   
    }
    task.resume()

    }
2
  • lsabekov show your code? Commented Mar 13, 2017 at 16:09
  • 3
    Possible duplicate of Swift 3 json parsing Commented Mar 13, 2017 at 16:28

1 Answer 1

2

No need to parse it. It's already a dictionary. You can access the value with key directly

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

1 Comment

Well, that's what I think "deserialize" means.

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.