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閱讀 134,923評論 18 139
  • # 一度蜜v3.0協議 --- # 交互協議 [TOC] ## 協議說明 ### 請求參數 下表列出了v3.0版協...
    c5e350bc5b40閱讀 670評論 0 0
  • 1.創建文件夾 !/bin/sh mkdir -m 777 "%%1" 2.創建文件 !/bin/sh touch...
    BigJeffWang閱讀 10,186評論 3 53
  • 昨夜與朋友敘舊,沒聊兩句他就唉聲嘆氣,詢問得知是感嘆自己老的快。 時光如禽獸,撕碎了一切,我抓著尾巴,跌跌撞撞,他...
    吳希道閱讀 249評論 0 1
  • 王建軍 5年前,他在選秀名單中位居最后一位。 人們都在拿他的身高說事,畢竟他只有175厘米,因為過去TD花園的主人...
    東營王建軍閱讀 953評論 0 5