iOS 网络JSon解析使用框架

个人使用RMMapper,git上面有。建立Model,然后解析,调理清晰。

以下是使用方法:

-------------XMBase----------------

#import

#import "RMMapper.h"

@interface XMBase : NSObject <RMMapping>

@end


#import "XMBase.h"

@implementation XMBase

@end


-------------Model----------------

#import

#import "XMBase.h"

@interface XMModelList : XMBase

@property (nonatomic,strong)NSArray *list;

@property (nonatomic,strong)NSString *type;

@property (nonatomic,strongNSString *code;

@end


#import "XMModelList.h"

#import "XMModelDetail.h"

@implementation XMModelList

- (Class)rm_itemClassForArrayProperty:(NSString *)property{

    if ([property isEqualToString:@"list"]) {

        return [XMModelDetail class];

    }

    return nil;

}

@end

------------- Model里的list ----------------

#import

@interface XMModelDetail : NSObject

@property (nonatomic,strong)NSString *app_name;

@property (nonatomic,strong)NSString *package_name;

@property (nonatomic,strongNSInteger *app_size;

@property (nonatomic,strong)NSString *install_time;

@end


#import "XMModelDetail.h"

@implementation XMModelDetail

@end


------------- 使用AFN请求返回的数据然后解析 ----------------

XMModelList *model = [RMMapperobjectWithClass:[XMModelListclass] fromDictionary:responseObject];



你可能感兴趣的:(iOS)