iOS 字典中含有字典的解析方法

服务器返回的数据如下:

reaname和headPhoto在字典的字典里.

其中字典中包含字典,解析方式如下:

运用MJ的解析, 创建一个模型ZTResponseItem

.h文件

 1 //
 2 //  ZTResponseItem.h
 3 //  HeHuJianKang
 4 //
 5 //  Created by zzt on 17/1/10.
 6 //  Copyright © 2017年 zzt. All rights reserved.
 7 //
 8 
 9 #import <Foundation/Foundation.h>
10 
11 @interface ZTResponseItem : NSObject
12 /** 姓名*/
13 @property (nonatomic, strong)NSString *realname;
14 @property (nonatomic, strong)NSString *headPhoto;
15 /** 内容*/
16 @property (nonatomic, strong)NSString *text;
17 @end

.m文件

 1 //
 2 //  ZTResponseItem.m
 3 //  HeHuJianKang
 4 //
 5 //  Created by zzt on 17/1/10.
 6 //  Copyright © 2017年 zzt. All rights reserved.
 7 //
 8 
 9 #import "ZTResponseItem.h"
10 
11 @implementation ZTResponseItem
12 + (NSDictionary *)mj_replacedKeyFromPropertyName
13 {
14     return @{
15              // 模型属性: JSON key, MJExtension 会自动将 JSON 的 key 替换为你模型中需要的属性
16              @"realname":@"doctor.realname",
17              @"headPhoto":@"doctor.headPhoto"
18              };
19 }
20 @end

这样在走通常的方式:字典转模型, 模型给控件赋值, OK!

 

posted on 2017-02-21 14:02  loveDoDream_zzt  阅读(299)  评论(0编辑  收藏  举报

导航