ios - How to create customised nsdictionary from two nsarrays -
i have 2 arrays this
idarray:( "548c2afe-5943-4929-9c6b-b544f5022115-sff45v-kjsa68f", "656e8481-f2d5-4843-bebd-883f1b0f79d0-ksfns-gg456gg" ) namesarray:( "king", "queen" )
i want make dictionary looks this
[{ "id" : "548c2afe-5943-4929-9c6b-b544f5022115-sff45v-kjsa68f", "name" : "king" }, { "id" : "3656e8481-f2d5-4843-bebd-883f1b0f79d0-ksfns-gg456gg", "name" : "queen" }]
help me in issue. have tried this
nsdictionary *fulldictionary = @{@"id": userarray, @"scandat": scandatesarray}; nserror *error; nsdata *data = [nsjsonserialization datawithjsonobject:fulldictionary options:0 error:&error]; nslog(@"%@", fulldictionary);
and output is
{ id = ( "656e8481-f2d5-4843-bebd-883f1b0f79d0", "548c2afe-5943-4929-9c6b-b544f5022115" ); scandat = ( "2016-05-28 16:50:30", "2016-05-28 16:50:59" ); }
you not making dictionary - target object nsarray
containing nsdictionary
objects elements.
nsmutablearray *res = [nsmutablearray array]; nsarray *keys = @[@"id", @"name"]; (int = 0 ; != idarray.count ; i++) { nsdictionary *dict = [nsdictionary dictionarywithobjects: @[idarray[i], namearray[i]] forkeys: keys ]; [res addobject:dict]; }
Comments
Post a Comment