ios - How to handle escaped emebed json within another JSON using Swift ObjectMapper -


i'm trying map json string data model using objectmapper. below json string i'm trying:

{   "username":"test",   "studentno":71129,   "activity":{     "name":"test name",     "semester":"1",     "activityhistory":"{ \"id\": \"111111\", \"items\": [ { \"datetime\": \"201923022016\", \"mediaformat\": \"online\" } ,{ \"datetime\": \"201923022016\", \"mediaformat\": \"online\" } ,{ \"datetime\": \"201923022016\", \"mediaformat\": \"online\" } ]}"   }  } 

the embedded json within json payload coming external api , have no control on it.

my model classes:

import uikit import objectmapper

    class studentmodel: mappable {         var username: string?         var studentno : string?         var activity : [activitymodel]?          init() {}          required init?(_ map: map) {         }          // mappable         func mapping(map: map) {             username             <- map["username"]             studentno         <- map["stno"]             activity            <- map["activity"]         }     }       class activitymodel: mappable {         var name: string?         var semester : int?         var activityhistory: string?          init() {}          required init?(_ map: map) {         }          // mappable         func mapping(map: map) {             name             <- map["name"]             semester         <- map["semester"]             activityhistory  <- map["activityhistory"]         }     } 

i don't seem able map json string , know issue activityhistroy since if change value of field simple ("test") , change model var activity : [activitymodel]? var activity : string? can whole thing mapped.

to map object:

var studentmodel = mapper<studentmodel>().map(json)! 

studentmodel.activity nil after above! can see doing wrong?

var activity : [activitymodel]? means expects array of activitymodel json posted not array. change var activity : [activitymodel]? var activity : activitymodel?.


Comments

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -