问题描述
- ios关于不会用sbjson创建json,请教
-
请问这种形式的json怎么创建 ,在下新手请给demo事例 ,项目中有sbjson库
{"code":"1","desc":[{"col_0007":"李玉华", "col_0023":"已回单","col_0025":"800.00", "col_0027":"T14101400008","col_0031":"2014-10-14 22:21:05", "col_0042":"null","col_0057":"null"},{"col_0007":"李丽", "col_0023":"已转单","col_0025":"0.00", "col_0027":"T14101400009","col_0031":"2014-10-14 22:33:49", "col_0042":"null","col_0057":"null"},{"col_0007":"安徽若达企业", "col_0023":"已回单","col_0025":"3423.00", "col_0027":"T14101400010","col_0031":"2014-10-14 22:37:00", "col_0042":"ZD2014101400024","col_0057":"null"},{"col_0007":"王海", "col_0023":"运输中","col_0025":"0.00", "col_0027":"T14101400011","col_0031":"2014-10-14 22:55:00", "col_0042":"null","col_0057":"null"},{"col_0007":"张峰", "col_0023":"已转单","col_0025":"0.00", "col_0027":"T14101400012","col_0031":"2014-10-14 23:11:22", "col_0042":"null","col_0057":"null"},{"col_0007":"安徽若达企业", "col_0023":"已回单","col_0025":"458.00", "col_0027":"T14101400013","col_0031":"2014-10-14 23:15:30", "col_0042":"ZD2014101400026","col_0057":"null"},{"col_0007":"安徽若达企业", "col_0023":"已回单","col_0025":"5634.00", "col_0027":"T14101400014","col_0031":"2014-10-14 23:34:36", "col_0042":"ZD2014101400029","col_0057":"null"}]}
解决方案
- (NSDictionary *)getDictionaryObj:(CartOrder *)cartOrder{
NSMutableDictionary *dic = [NSMutableDictionary dictionary];
[dic setObject:@(cartOrder.merchantId) forKey:@"merchantId"];
[dic setObject:cartOrder.goodsId forKey:@"goodsId"];
[dic setObject:cartOrder.myRequest forKey:@"myRequest"];
[dic setObject:cartOrder.count forKey:@"count"];
[dic setObject:cartOrder.sendTime forKey:@"sendTime"];
[dic setObject:@(cartOrder.seatId) forKey:@"seatId"];
return [dic copy];
}
解决方案二:
NSJSONSerialization dataWithJSONObject:(id)object options:0 error:nil 可以将OC对象转化成JSON.你自定义的对象要自己包装成字典
时间: 2024-12-02 18:15:21