Create JSON in swift -



Create JSON in swift -

i need create json this:

order = { type_id:'1',model_id:'1', transfer:{ startdate:'10/04/2015 12:45', enddate:'10/04/2015 16:00', startpoint:'Ул. Момышулы, 45', endpoint:'Аэропорт Астаны' }, hourly:{ startdate:'10/04/2015', enddate:'11/04/2015', startpoint:'ЖД Вокзал', endpoint:'', undefined_time:'1' }, custom:{ startdate:'12/04/2015', enddate:'12/04/2015', startpoint:'Астана', endpoint:'Павлодар', customprice:'50 000' }, commenttext:'', device_type:'ios' };

the problem can not create valid json. here how create object:

let jsonobject: [anyobject] = [ ["type_id": singlestructdataofcar.typeid, "model_id": singlestructdataofcar.modelid, "transfer": saveddatatransfer, "hourly": saveddatahourly, "custom": saveddatareis, "device_type":"ios"] ]

where saveddata dictionaries:

let saveddata: nsdictionary = ["servicedatastartdate": singlestructdata.startofwork, "servicedataaddressofreq": singlestructdata.addressofrequest, "servicedataaddressofdel": singlestructdata.addressofdelivery, "servicedatadetailedtext": singlestructdata.detailedtext, "servicedataprice": singlestructdata.priceproposed]

when utilize strings creating json object works fine. when include dictionaries nsjsonserialization.isvalidjsonobject(value) returns false. how can create valid dictionary?

one problem code not of type dictionary.

let jsonobject: [anyobject] = [ [ "type_id": singlestructdataofcar.typeid, "model_id": singlestructdataofcar.modelid, "transfer": saveddatatransfer, "hourly": saveddatahourly, "custom": saveddatareis, "device_type":"ios" ] ]

the above array of anyobject dictionary of type [string: anyobject] within of it.

try match json provided above:

let saveddata = ["something": 1] allow jsonobject: [string: anyobject] = [ "type_id": 1, "model_id": 1, "transfer": [ "startdate": "10/04/2015 12:45", "enddate": "10/04/2015 16:00" ], "custom": saveddata ] allow valid = nsjsonserialization.isvalidjsonobject(jsonobject) // true

json swift object

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -