需要解析的數(shù)據(jù)格式如下圖
解析前說明:
1.使用MJExtension
2.一個字典,就是一個模型.因此這里需要創(chuàng)建兩個模型類,分別是FKGoodsOrderModel
,FKGoodsModelInOrder
解析步驟
- 第一步:創(chuàng)建兩個模型類(模型類集成NSObject)
FKGoodsOrderModel
文件內容如下
// .h文件==============================
#import <Foundation/Foundation.h>
@class FKGoodsModelInOrder;
@interface FKGoodsOrderModel : NSObject
@property(nonatomic, assign) double sumPrice;
@property(nonatomic, assign) double sumCurrency;
@property(nonatomic, assign) NSInteger sumNumber;
@property(nonatomic, assign) NSInteger orderStatus;
@property(nonatomic, copy) NSString *barName;
@property(nonatomic, strong) NSMutableArray <FKGoodsModelInOrder *>*products;
@end
// .m文件(重點)==============================
#import "FKGoodsOrderModel.h"
@implementation FKGoodsOrderModel
+ (NSDictionary *)mj_objectClassInArray {
// 表明你products數(shù)組存放的將是FKGoodsModelInOrder類的模型
return @{
@"products" : @"FKGoodsModelInOrder",
};
}
@end
FKGoodsModelInOrder
文件內容如下:
// .h文件==============================
#import <Foundation/Foundation.h>
@interface FKGoodsModelInOrder : NSObject
@property(nonatomic, assign) NSInteger MethodPay;
@property(nonatomic, assign) double price;
@property(nonatomic, assign) NSInteger number;
@property(nonatomic, copy) NSString *name;
@property(nonatomic, copy) NSString *attribute;
@property(nonatomic, copy) NSString *img;
@property(nonatomic, copy) NSString *createTime;
@end
// .m文件(啥都沒寫)
#import "FKGoodsModelInOrder.h"
@implementation FKGoodsModelInOrder
@end
- 第二步:在返回上圖數(shù)據(jù)的控制器中,導入這兩個頭文件
#import "FKGoodsOrderModel.h"
#import "FKGoodsModelInOrder.h"
- 第三步:利用外層模型(FKGoodsOrderModel)調用MJExtension的
mj_objectArrayWithKeyValuesArray:responseObject[@"data"]
方法
self.goodsOrderModelArray = [FKGoodsOrderModel mj_objectArrayWithKeyValuesArray:responseObject[@"data"]];
至此結束