JSON Accelerator 數(shù)組的遍歷

平時寫項目習(xí)慣用?JSON Accelerator 進行json 數(shù)據(jù)的處理,有時遇到問題找度娘發(fā)現(xiàn)對JSON Accelerator的介紹都比較籠統(tǒng),這里記錄下我的使用心得,希望幫助有需要的朋友

這里我就用項目里的數(shù)據(jù)進行演示,簡單的json數(shù)據(jù)網(wǎng)上有很多教程,這里就不演示了,接下來演示下json數(shù)據(jù)中包含數(shù)組時的使用方法

{

"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 數(shù)據(jù) 的result 對應(yīng)的是一個數(shù)組?

用JSON Accelerator 生成的文件



導(dǎo)入頭文件?

#import "DataModels.h"

在需要調(diào)用的方法中

//傳入字典

ImageSweepBaseClass * base = [ImageSweepBaseClass modelObjectWithDictionary:dic];

相關(guān)屬性可打點調(diào)用了?

下面是遍歷數(shù)組

//這里的?ImageSweepResult 中包含了sitePhotoDO,siteProfileDO兩個對象

//base.result 為對象中的數(shù)組

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];

}

具體的取值就是這個樣子,希望能幫助有需要的朋友

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Spring Cloud為開發(fā)人員提供了快速構(gòu)建分布式系統(tǒng)中一些常見模式的工具(例如配置管理,服務(wù)發(fā)現(xiàn),斷路器,智...
    卡卡羅2017閱讀 136,590評論 19 139
  • # 一度蜜v3.0協(xié)議 --- # 交互協(xié)議 [TOC] ## 協(xié)議說明 ### 請求參數(shù) 下表列出了v3.0版協(xié)...
    c5e350bc5b40閱讀 737評論 0 0
  • 1.創(chuàng)建文件夾 !/bin/sh mkdir -m 777 "%%1" 2.創(chuàng)建文件 !/bin/sh touch...
    BigJeffWang閱讀 10,495評論 3 53
  • 昨夜與朋友敘舊,沒聊兩句他就唉聲嘆氣,詢問得知是感嘆自己老的快。 時光如禽獸,撕碎了一切,我抓著尾巴,跌跌撞撞,他...
    吳希道閱讀 318評論 0 1
  • 王建軍 5年前,他在選秀名單中位居最后一位。 人們都在拿他的身高說事,畢竟他只有175厘米,因為過去TD花園的主人...
    東營王建軍閱讀 996評論 0 5

友情鏈接更多精彩內(nèi)容