objective c - Editing an NSMutableDictionary sub-dictionary -
i have nsmutabledictionary made json
file.
nsmutabledictionary *result=//from json string
than , need edit result
,which built :
{ slots = ( { capacity = 1; slot = sybiwqgdww; taken = ( "11:45-12:45", "12:45-17:45" ); }, { capacity = 1; slot = wnysjezamu; taken = ( "12:00-13:00", "13:00-18:00" ); } ); }
to array of fields have :
nsmutablearray *slots=[result objectforkey:@"slots"];
than dictionaries :
for(nsmutabledictionary *dic in slots) [dic setobject:@"1" forkey:@"slot"];//crash because edit in loop
now crash when trying change field in loop.
how can change field ?
edit
this how make dictionary json (which mutable copy result! )
-(nsdictionary*)getdictionaryforjsonwithstring:(nsstring*)string { nsstring *datastring=string; nsdata *mydata=[datastring datausingencoding:nsasciistringencoding]; nserror *error; nsdictionary *datadic = [nsjsonserialization jsonobjectwithdata:mydata options:kniloptions error:&error]; //nslog(@"getdictionaryforjsonwithstring: data is: %@",datadic); return datadic; } nsmutabledictionary *result=[[self getdictionaryforjsonwithstring:json] mutablecopy];
when create dictionary json, need set option create mutable instances, , should both containers , leaves:
option: nsjsonreadingmutablecontainers | nsjsonreadingmutableleaves
Comments
Post a Comment