第一:下载JSONExport工具: https://github.com/Ahmed-Ali/JSONExport 运行后如图一:
图一.png第二:将接口获取的网络数据 ,按图二操作
图二.png
第三:点保存后 会生成 如图三的文件:
图三.png
在 RootClass.swift 文件中 保留 如图的 格式 ,其他代码删除
RootClass.swift.png其他文件 中的代码 也按这样的格式 ,复制到 这个文件中,然后再把这个文件拖进 项目中(RootClass.swift 可以随意改成你要 名称,如这里改成了UserModel)
最后的模型文件
// RootClass.swift
//
// Create by Mac on 7/8/2017
// Copyright © 2017. All rights reserved.
// Model file generated using JSONExport: https://github.com/Ahmed-Ali/JSONExport
import Foundation
import ObjectMapper
class UserModel : Mappable{
var sid : String?
var succeed : Int?
var timeUsage : String?
var user : User?
required init?(map: Map){}
func mapping(map: Map)
{
sid <- map["sid"]
succeed <- map["succeed"]
timeUsage <- map["time_usage"]
user <- map["user"]
}
}
class User : Mappable{
var age : Int?
var avatar : Avatar?
var brief : String?
var cancelOrderNum : Int?
var carColor : String?
var carStatus : CarStatu?
var carVersion : String?
var commentCount : Int?
var commentGoodrate : Float?
var gender : Int?
var id : Int?
var incomeAmount : String?
var joinedAt : String?
var licensePlate : String?
var mobilePhone : String?
var nickname : String?
var orderAmount : Int?
var qrcode : String?
var services : Service?
var signature : String?
var successRate : String?
var userGroup : Int?
required init?(map: Map){}
func mapping(map: Map)
{
age <- map["age"]
avatar <- map["avatar"]
brief <- map["brief"]
cancelOrderNum <- map["cancel_order_num"]
carColor <- map["car_color"]
carStatus <- map["car_status"]
carVersion <- map["car_version"]
commentCount <- map["comment_count"]
commentGoodrate <- map["comment_goodrate"]
gender <- map["gender"]
id <- map["id"]
incomeAmount <- map["income_amount"]
joinedAt <- map["joined_at"]
licensePlate <- map["license_plate"]
mobilePhone <- map["mobile_phone"]
nickname <- map["nickname"]
orderAmount <- map["order_amount"]
qrcode <- map["qrcode"]
services <- map["services"]
signature <- map["signature"]
successRate <- map["success_rate"]
userGroup <- map["user_group"]
}
}
class Service : Mappable{
var daijia : Int?
var kuaiche : Int?
var kuaidi : Int?
var shunfengche : Int?
var zhuanche : Int?
required init?(map: Map){}
func mapping(map: Map)
{
daijia <- map["daijia"]
kuaiche <- map["kuaiche"]
kuaidi <- map["kuaidi"]
shunfengche <- map["shunfengche"]
zhuanche <- map["zhuanche"]
}
}
class CarStatu : Mappable{
var carStatus : Int?
var serviceType : Int?
required init?(map: Map){}
func mapping(map: Map)
{
carStatus <- map["car_status"]
serviceType <- map["service_type"]
}
}
class Avatar : Mappable{
var height : Int?
var large : String?
var thumb : String?
var width : Int?
required init?(map: Map){}
func mapping(map: Map)
{
height <- map["height"]
large <- map["large"]
thumb <- map["thumb"]
width <- map["width"]
}
}
网友评论