簡體   English   中英

如何從字典iOS數組獲取JSON數據解析

[英]How to get JSON data parse from Arrays of dictionary iOS

list = ({
    clouds = 24;
    speed = "4.31";
    temp = {
        day = "283.84";
        eve = "283.84";
        night = "283.84";
    };
}),

請誰能告訴我我在做什么錯-我想先在表中顯示list-> temp-> day值,我試圖在要終止的數組中獲取數據。 這是我的代碼,我做錯了什么

NSDictionary *json = [NSJSONSerialization JSONObjectWithData:dataBuffer options:-1 error:nil];

NSLog(@"%@",json);

NSMutableDictionary * list = [json objectForKey:@"list"];

NSMutableArray *arrays = [[NSMutableArray alloc]initWithCapacity:0];

for (NSDictionary *lists in [list allValues]) {
    [arrays addObject:[list valueForKey:@"temp"]];
}

如果要訪問日期,請使用下面的行,

NSString *day = [json valueForKeyPath:@"list.temp.day"];

您的列表是一個數組,因此,如果您希望在不做太大改變的情況下進行操作,則可以替換為:

NSMutableDictionary * list = [json objectForKey:@"list"];

附:

NSMutableDictionary * list = [[json objectForKey:@"list"] objectAtIndex:0];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM