JSON Accelerator 数组的遍历

平时写项目习惯用 JSON Accelerator 进行json 数据的处理,有时遇到问题找度娘发现对JSON Accelerator的介绍都比较笼统,这里记录下我的使用心得,希望帮助有需要的朋友

这里我就用项目里的数据进行演示,简单的json数据网上有很多教程,这里就不演示了,接下来演示下json数据中包含数组时的使用方法

{

"status" : 0,

"result" : [

{

"siteProfileDO" : {

"siteId" : 12,

"ext2" : null,

"subBizType" : null,

"gmtCreate" : 1508988069000,

"profileType" : 1,

"gmtModified" : 1509901774000,

"ext1" : null,

"createUser" : 1,

"profileName" : "乐呗",

"profileValue" : "http:\/\/uni.com\/addressMSF\/product.html",

"profileCode" : "appMiddleCarouselFigure1",

"sitePhotoId" : 53,

"bizType" : 3,

"siteProfileId" : 56,

"modifyUser" : 15,

"ext3" : null,

"status" : 1

},

"sitePhotoDO" : {

"siteId" : 12,

"digest" : null,

"photoPath" : "\/MSF_IMGS\/oem_12\/1\/",

"photoType" : 0,

"gmtCreate" : 1508988069000,

"gmtModified" : null,

"sitePhotoType" : 3,

"createUser" : 1,

"modifyUser" : null,

"sitePhotoId" : 53,

"photoName" : "site_photo_2017102611210804729.png",

"status" : 1

}

},

{

"siteProfileDO" : {

"siteId" : 12,

"ext2" : null,

"subBizType" : null,

"gmtCreate" : 1508988069000,

"profileType" : 1,

"gmtModified" : 1509901774000,

"ext1" : null,

"createUser" : 1,

"profileName" : "会员卡",

"profileValue" : "http:\/\/uniom\/addressMSF\/product.html",

"profileCode" : "appMiddleCarouselFigure2",

"sitePhotoId" : 54,

"bizType" : 3,

"siteProfileId" : 57,

"modifyUser" : 15,

"ext3" : null,

"status" : 1

},

"sitePhotoDO" : {

"siteId" : 12,

"digest" : null,

"photoPath" : "\/MSF_IMGS\/oem_12\/1\/",

"photoType" : 0,

"gmtCreate" : 1508988069000,

"gmtModified" : null,

"sitePhotoType" : 3,

"createUser" : 1,

"modifyUser" : null,

"sitePhotoId" : 54,

"photoName" : "site_photo_2017102611210904094.png",

"status" : 1

}

},

{

"siteProfileDO" : {

"siteId" : 12,

"ext2" : null,

"subBizType" : null,

"gmtCreate" : 1508988069000,

"profileType" : 1,

"gmtModified" : 1509901774000,

"ext1" : null,

"createUser" : 1,

"profileName" : "信用卡申请",

"profileValue" : "http:\/\/unicom\/addressMSF\/product.html",

"profileCode" : "appMiddleCarouselFigure3",

"sitePhotoId" : 55,

"bizType" : 3,

"siteProfileId" : 58,

"modifyUser" : 15,

"ext3" : null,

"status" : 1

},

"sitePhotoDO" : {

"siteId" : 12,

"digest" : null,

"photoPath" : "\/MSF_IMGS\/oem_12\/1\/",

"photoType" : 0,

"gmtCreate" : 1508988069000,

"gmtModified" : null,

"sitePhotoType" : 3,

"createUser" : 1,

"modifyUser" : null,

"sitePhotoId" : 55,

"photoName" : "site_photo_2017102611210970416.png",

"status" : 1

}

}

],

"paging" : null,

"countResult" : null,

"code" : null,

"message" : null,

"failures" : null

}

这个json 数据 的result 对应的是一个数组 

用JSON Accelerator 生成的文件



导入头文件 

#import "DataModels.h"

在需要调用的方法中

//传入字典

ImageSweepBaseClass * base = [ImageSweepBaseClass modelObjectWithDictionary:dic];

相关属性可打点调用了 

下面是遍历数组

//这里的 ImageSweepResult 中包含了sitePhotoDO,siteProfileDO两个对象

//base.result 为对象中的数组

for (ImageSweepResult * result in base.result ) {

[mArray addObject:[NSString stringWithFormat:@"%@%@%@", API_SERVER,result.sitePhotoDO.photoPath, result.sitePhotoDO.photoName]];

[self.nameArray addObject:result.siteProfileDO.profileName];

[self.urlArray addObject:result.siteProfileDO.profileValue];

}

具体的取值就是这个样子,希望能帮助有需要的朋友

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 135,288评论 19 139
  • # 一度蜜v3.0协议 --- # 交互协议 [TOC] ## 协议说明 ### 请求参数 下表列出了v3.0版协...
    c5e350bc5b40阅读 686评论 0 0
  • 1.创建文件夹 !/bin/sh mkdir -m 777 "%%1" 2.创建文件 !/bin/sh touch...
    BigJeffWang阅读 10,269评论 3 53
  • 昨夜与朋友叙旧,没聊两句他就唉声叹气,询问得知是感叹自己老的快。 时光如禽兽,撕碎了一切,我抓着尾巴,跌跌撞撞,他...
    吴希道阅读 270评论 0 1
  • 王建军 5年前,他在选秀名单中位居最后一位。 人们都在拿他的身高说事,毕竟他只有175厘米,因为过去TD花园的主人...
    东营王建军阅读 969评论 0 5