objective c - JSON to NSMutableArray iOS -
as response request json:
{ "letters": { "a": 0, "b": 1, "c": 2, "d": 3, "e": 4, ... } }
that's code acquire json:
nsurlrequest *request = [nsurlrequest requestwithurl:[nsurl urlwithstring:url]]; afhttprequestoperation *operation = [[afhttprequestoperation alloc] initwithrequest:request]; operation.responseserializer = [afjsonresponseserializer serializer]; [operation setcompletionblockwithsuccess:^(afhttprequestoperation *operation, id responseobject) { nslog(@"%@", responseobject); } failure:^(afhttprequestoperation *operation, nserror *error) { // handle error }];
i want fill array keys (not values) this:
array[0] = "a"
array[1] = "b" ...?
nsmutablearray *parts = [nsmutablearray new]; nsdictionary *allletters = [responseobject objectforkey:@"letters"]; (nsstring *key in [allletters allkeys]) { nsstring *value = [allletters objectforkey: key]; [parts insertobject:key atindex:[val intvalue]]; }
Comments
Post a Comment