Reading JSON with multiple dictionaries and arrays into Swift -


i trying separate out before, range , after json below , store them in different arrays/dictionaries. able parse range. can please example?

{     "before": [         {             "segment": 1,             "end": 0,             "size": 0         },         {             "segment": 2,             "end": 0.01,             "size": 0.1         }     ],     "range": [         100,         101,         102,         103,         104,         105,         106,         107,         108,         109,         110     ],     "after": [         {             "segment": 1,             "end": 0,             "size": 0         },         {             "segment": 2,             "end": 0.5,             "size": 0.1         },         {             "segment": 3,             "end": 0.8,             "size": 0.3         },         {             "segment": 4,             "end": 1,             "size": 0.5         }     ] } 

all have cast content right type.

you json object dictionary; "before" array of dictionaries, "after" similar, , "range" array of ints.

knowing this, it's easy decode:

if let json = try? nsjsonserialization.jsonobjectwithdata(data, options: []) {     if let dict = json as? [string:anyobject] {         if let before = dict["before"] as? [[string:anyobject]] {             print(before)         }         if let after = dict["after"] as? [[string:anyobject]] {             print(after)         }         if let range = dict["range"] as? [int] {             print(range)         }     } } 

Comments

Popular posts from this blog

wireshark - USB mapping with python -

c++ - nodejs socket.io closes connection before upgrading to websocket -

Deploying Qt Application on Android is really slow? -