objective c - How to rearrange NSDictionary according to the values? -



objective c - How to rearrange NSDictionary according to the values? -

i need list dictionary values. highest mark lowest. how can handle this?

i need list marks , corresponding names , details in table view.

2015-04-06 14:48:53.381 camelproject[3310:597950] valueforkey title = ( { camelid = 237; color = bg; comments = "fhjfnfnfjfihgjfmsndidm,almcmcuirowmvn vmmc jdmdmcm"; compid = 235; dateofbirth = "/date(1424725200000)/"; description = "rtrtttrtrehndskvn;lkdf;lm;mgemln;lm';' jknt;l"; fromuserid = 564987631; fromusername = 564987631; id = 4; indvmarks = "5;5;3;4;2;2;2;2;5;9"; marks = 39; name = name3sv; outof = 100; profilephoto = "2d0b36f3-71b3-4b5f-a375-7ad4d0aff1af.jpg\n"; toname = hasnam; tousername = 564987631; types = dsfv; userid = 564987631; fromname = hasnam; }, { camelid = 237; color = bg; comments = ""; compid = 235; dateofbirth = "/date(1424725200000)/"; description = "rtrtttrtrehndskvn;lkdf;lm;mgemln;lm';' jknt;l"; fromuserid = 564987631; fromusername = 564987631; id = 5; indvmarks = "5;4;5;7;6;0;6;5;4;6"; marks = 48; name = name3sv; outof = 100; profilephoto = "2d0b36f3-71b3-4b5f-a375-7ad4d0aff1af.jpg\n"; toname = hasnam; tousername = 564987631; types = dsfv; userid = 564987631; fromname = hasnam; }, { camelid = 237; color = bg; comments = gucjhkhvnkvnvnvknkjbkvjhvvkb; compid = 235; dateofbirth = "/date(1424725200000)/"; description = "rtrtttrtrehndskvn;lkdf;lm;mgemln;lm';' jknt;l"; fromuserid = 564987631; fromusername = 564987631; id = 6; indvmarks = "3;4;4;3;5;4;4;3;3;5"; marks = 38; name = name3sv; outof = 100; profilephoto = "2d0b36f3-71b3-4b5f-a375-7ad4d0aff1af.jpg\n"; toname = hasnam; tousername = 564987631; types = dsfv; userid = 564987631; fromname = hasnam; }, { camelid = 236; color = wejr; comments = "jfj ki idhvjfn isms isn't if jfj jen hik"; compid = 235; dateofbirth = "/date(1427058000000)/"; description = jwenrfernkgr; fromuserid = 564987631; fromusername = 564987631; id = 21; indvmarks = "8;6;10;10;10;7;5;8;9;5"; marks = 78; name = name; outof = 100; profilephoto = "e7735af4-8eab-41e7-a3f2-3280dbed0389.jpg\n"; toname = lukman; tousername = 564987634; types = wenjewfn; userid = 564987634; fromname = hasnam; } )

get values array , sort them using sort descriptor.

nsarray *array = [dictioanry objectforkey:@"title"]; nssortdescriptor* marksdescriptor = [nssortdescriptor sortdescriptorwithkey:@"marks" ascending:yes]; nsarray* sortedobjects = [array sortedarrayusingdescriptors:[nsarray arraywithobjects:marksdescriptor, nil]]; //you can set object nsdictionary if want later

i think dictionary should looking this.

so code above should work sort values. here sample code did testing with.

note: save json string in test.json , add together project. or download file here , add together project

nsstring *filepath = [[nsbundle mainbundle] pathforresource:@"test" oftype:@"json"]; nsdata *data = [nsdata datawithcontentsoffile:filepath]; nsdictionary *jsondictionary=[nsjsonserialization jsonobjectwithdata:data options:nsjsonreadingmutableleaves error:nil]; nslog(@"%@",jsondictionary); nsarray *array = [jsondictionary objectforkey:@"title"]; nssortdescriptor* marksdescriptor = [nssortdescriptor sortdescriptorwithkey:@"marks" ascending:yes]; nsarray* sortedobjects = [array sortedarrayusingdescriptors:[nsarray arraywithobjects:marksdescriptor, nil]]; nslog(@"%@",sortedobjects);

objective-c json nsdictionary

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -