iOS ObjectMapper

1. Json(dictionary) -> Object

headerData = userInfoModel(JSON: json1.dictionaryObject ?? [:])


2. Json(Array) -> Objcet

listData = Mapper().mapArray(JSONArray: json2.arrayObject as! [[String : Any]])


3.Create Model

import ObjectMapper

class userInfoModel:Mappable{

    var username =""

    var  nick =""

    var image =""

    var avatar =""


    requiredinit?(map:Map) {


    }


    funcmapping(map:Map) {

        username<- map["username"]

        nick<- map["nick"]

        image<- map["image"]

        avatar<- map["avatar"]

    }


}

你可能感兴趣的:(iOS ObjectMapper)