今天做公司的專案,遇到乙個問題,我使用adn進行網路連線,伺服器返回給我乙個字典,但是我需要的內容又是字典中的乙個陣列。我如何才能得到我想要的字典呢?
found = 600;
num = 10;
"time_used" = "0.028";
total = 177837;
"total_page" = 60;
datalist = (
);
這是資料庫返回來的json格式。我們想要的內容是datalist中的模型。為了獲取這個模型廢了我好長時間。現在把經驗總結一下:
來看一下mj提供的參考
@inte***ce
ad : nsobject
@property (copy, nonatomic) nsstring *image;
@property (copy, nonatomic) nsstring *url;
@end
@inte***ce
statusresult : nsobject
/** 存放著一堆的微博資料(裡面都是status模型) */
@property (strong, nonatomic) nsmutablearray *statuses;
/** 存放著一堆的廣告資料(裡面都是ad模型) */
@property (strong, nonatomic) nsarray *ads;
@property (strong, nonatomic) nsnumber *totalnumber;
@end
@implementation
statusresult
// 實現這個方法的目的:告訴mjextension框架statuses和ads陣列裡面裝的是什麼模型
+ (nsdictionary *)objectclassinarray;}
@end
nsdictionary *dict = @},@
}],
@"ads" : @[@,@
],@"totalnumber" : @"2014"
};// 將字典轉為statusresult模型
statusresult *result = [statusresult objectwithkeyvalues:dict];
nslog(@"totalnumber=%@", result.totalnumber);
// totalnumber=2014
// 列印statuses陣列中的模型屬性
for (status *status in result.statuses)
// text=今天天氣真不錯!, name=rose, icon=nami.png
// text=明天去旅遊了, name=jack, icon=lufy.png
// 列印ads陣列中的模型屬性
for (ad *ad in result.ads)
// image=ad01.png, url=
// image=ad02.png, url=
非常重要的一段**:
;
}
通過這種方式我得到了模型陣列,這樣在現實訊息的使用我們就可以直接使用模型來設定內容了
wzstore *store = self.stores[indexpath.row];
cell.main_do.text = store.main_do;
我們這樣就可以取出每一行所對應的模型了.
大概就是這樣,如果新內容會繼續補充.
MCV中字典轉模型的KVC底層實現
instancetype initwithdictionary nsdictionary dict return self 遍歷字典裡面所有的key和值,name,icon enumeratekeysandobjectsusingblock 遍歷字典中的所有keys和valus dict enume...
關於安裝centos中遇到的問題
安裝centos6.7的問題 centos 6.3 i386 livecd.iso是引導盤,作為維護工具,沒有安裝過程,直接就可以登入了。你所有的操作是不會被儲存的,想儲存檔案建議是安裝 版本的。這是國外的安裝centos7.0的過程。安裝gnome圖形介面 yum groupinstall gno...
OC YYModel字典轉模型的幾種詳細用法
目錄 常用的幾個方法 json轉模型 instancetype yy modelwithjson id json 模型轉字串 nsstring yy modeltojsonstring 字典轉模型 instancetype yy modelwithdictionary nsdictionary di...