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

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -