原问题来自于CSDN问答频道,更多解决方案见:http://ask.csdn.net/questions/2265
问题描述:
在nsdictionary中保存json解析的结果:
{ "statusCode":"200", "body":[ { "status":"success", "remarks":null } ], "data":[ "abcd":[ { "category":"a", "title":"b", "id":"24" }, { "category":"c", "title":"crd", "id":"65" }, { "category":"ds", "title":"sd", "id":"18" } ] }, { "efgh":[ { "category":"ds", "title":"sd", "id":"18" }, { "category":"sd", "title":"sd", "id":"1" } ] }, { "ijkl":[ { "category":"ds", "title":"sd", "id":"18" }, { "category":"sd", "title":"sd", "id":"1" } ] } ] }
NSMutableArray *getdata=[[NSMutableArray alloc]init]; getcat=[results objectForKey:@"data"];
下面应该怎么设置在第一个索引中的values(category, title, id)
。比如'abcd'?
谢谢
解决方案:getdata 里面应该是 3个NSDictionary 分别是
{ "category":"a", "title":"b", "id":"24" }, { "category":"c", "title":"crd", "id":"65" }, { "category":"ds", "title":"sd", "id":"18" }
NSDictionary *firstDic = [getdata objectAtIndex:0]; [firstDic setValue:@"new category" forKey:@"category"]; [firstDic setValue:@"new title" forKey:@"title"]; [firstDic setValue:@"new id" forKey:@"id"];