1.I從Web服務得到JSON數據,並將其添加對NSDictionary中GET值不起作用
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
2.然後我秀 「DIC」 中的NSLog這是目前
{"query": [{"IndexNo": 1,"ID": "01","Picture": "img/food-48.png"}]}
3 。然後我在新的NSDictionary「DIC」獲取數據值「DT」
NSDictionary *dt = [dic objectForKey: @"query"];
4.然後我的NSLog顯示「DT」這是目前
({ID = 01;IndexNo = 1;Picture = "img/food-48.png";})
5.我想從「dt」中獲得「ID」。我用這個代碼
NSString *ID = [dt objectForKey: @"ID"];
,但你可以試試這個
NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableLeaves error:&error];
NSArray *arr = [dic objectForKey: @"query"];
NSDictionary *dt = arr[0];
NSString *ID = [dt objectForKey: @"ID"];
是ID的值是否是NSString對象? – LML