How do I manipulate nested dictionaries in Swift, e.g. JSON data?

前端 未结 3 989
我在风中等你
我在风中等你 2020-12-09 11:01

I\'m using NSJSONSerialization to parse JSON in a Swift application. However, the returned dictionary consists of a complicated, deeply nested structure, making it impractic

3条回答
  •  旧时难觅i
    2020-12-09 11:40

    Just grab a reference to your json data as an NSDictionary:

    var dict: NSDictionary = NSJSONSerialization.JSONObjectWithData(data, options: NSJSONReadingOptions.MutableContainers, error: nil) as NSDictionary
    

    then you can reference it using subscripts:

    var myValue: NSString = dict["level1"]["level2"]
    

提交回复
热议问题