nsdictionary

Description of NSDictionary - why are some key names with quotes?

♀尐吖头ヾ 提交于 2019-12-01 02:12:12
问题 I used a simple NSLog on a dictionary: NSLog(@"dict %@", dictionary); the result was: ... "first_name" = Peter; gender = male; id = 1171548848; "last_name" = Lapisu; ... Why are some key names in "quotes" and some not? 回答1: When the string has characters apart from alphabets + numerics, it will quote the string. This is the basic methodology of the description function. 来源: https://stackoverflow.com/questions/11538371/description-of-nsdictionary-why-are-some-key-names-with-quotes

How to create JSON from a dictionary in Swift 4?

限于喜欢 提交于 2019-12-01 02:09:21
问题 Edit: I have read the other answers on SO for the same issue , however Im unable to get the desired output. I have tried many variations as suggested in other questions but its not working. I have a JSON snipped which needs to be added as the body when I open a websocket. sender: "system1@example.com", recipients:"system2@example.com", data: { text: "Test Message" }, So using Swift I did the following, var messageDictionary : [String: Any] = [ "sender": "system1@example.com", "recipients":

iOS Using NSDictionary to load data into section and rows

若如初见. 提交于 2019-12-01 01:08:39
I wish to display table section with date as the section title and name of book in the row. I'm all lost at how to use a NSDictionary to load data into section and rows. Therefore my codes are all screwed up :( Can anyone offer some help, with some sample codes as a guide? My NSMutableArray is as followed: ( { BIBNo = 187882; date = "14/08/2012"; itemSequence = 000010; name = "Increasing confidence / Philippa Davies."; noOfRenewal = 0; number = 000187907; status = "Normal Loan"; time = "24:00"; type = Loans; }, { BIBNo = 291054; date = "14/08/2012"; itemSequence = 000010; name = "iPhone

insertObject: atIndex: - index 3 beyond bounds for empty array

谁说我不能喝 提交于 2019-12-01 00:57:40
I create an array based on a dictionaries key's: factsBuiltArray = [NSMutableArray arrayWithCapacity: 6]; if ([statusDict count] == 10) { for (NSString *key in [statusDict allKeys]) { if ([key isEqualToString: @"currenciesAndConversions"]) { [factsBuiltArray insertObject:key atIndex: 0]; } else if ([key isEqualToString: @"languageAndTranslations"]) { [factsBuiltArray insertObject:key atIndex: 1]; } else if ([key isEqualToString: @"plugSize"]) { [factsBuiltArray insertObject:key atIndex: 2]; } else if ([key isEqualToString: @"timezone"]) { [factsBuiltArray insertObject:key atIndex: 3]; //

Help parsing a nested JSON object

橙三吉。 提交于 2019-11-30 23:09:15
I have the following JSON : { "meta": { "code": 200 }, "response": { "deals": [ { "id": 32373, "date_added": "2011-01-13 12:12:50", "end_date": "2011-01-14 10:00:00", "active": 1, "discount": { "raw": 71, "formatted": "71%" }, "price": { "raw": "85.00", "formatted": "$85" }, "value": { "raw": "300.00", "formatted": "$300" }, "purchased": 82, "left": null, "title": "$85 For $300 Babyface Facial At Park Avenue MedSpa", "yipit_title": "71% off Babyface Facial", "url": "http://yipit.com/aff/click/?deal=AvwTADtE&key=F374EFbM", "yipit_url": "http://yipit.com/new-york/livingsocial/85-for-300-babyface

Sort NSArray of NSDictionaries by string date in key?

泪湿孤枕 提交于 2019-11-30 20:45:29
I have been struggling to find an easy way to sort an NSMutableArray that contains NSDictionaries. Each NSDictionary has a key named "Date" which contains an NSString of a date (ex: 10/15/2014). What I am looking to do is sort the array based on those strings in ascending order. I have tried this with no luck: NSComparisonResult dateSort(NSString *s1, NSString *s2, void *context) { NSDateFormatter *formatter = [[NSDateFormatter alloc] init]; [formatter setDateFormat:@"MM/dd/yy"]; NSDate *d1 = [formatter dateFromString:s1]; NSDate *d2 = [formatter dateFromString:s2]; return [d1 compare:d2]; //

Adding keys to Nested NSDictionary

允我心安 提交于 2019-11-30 20:36:53
I am having problems creating new keys for a Nested NSDictionary. Here's what I have done I have this kind of NSMutableDictionary NSMutableDictionary *Ga=[NSMutableDictionary dictionaryWithDictionary:@{@"Node1" :@{@"SubNode11" :@40,@"SubNode12":@30}}]; Which NSLogs as: Node1 = { SubNode11 = 40; SubNode12 = 30; }; Now to add another root key and a nested key I did this, [Ga setObject:@{@"SubNode21" : @555} forKey:@"Node2"]; Now the NSLog outputs: Node1 = { SubNode11 = 40; SubNode12 = 30; }; Node2 = { SubNode21 = 555; }; } I need to add another key to an existing Node, say SubNode22=345; for

Sort array into dictionary

邮差的信 提交于 2019-11-30 20:13:39
I have and array of many strings. I wan't to sort them into a dictionary, so all strings starting the same letter go into one array and then the array becomes the value for a key; the key would be the letter with which all the words in it's value's array begin. Example Key = "A" >> Value = "array = apple, animal, alphabet, abc ..." Key = "B" >> Value = "array = bat, ball, banana ..." How can I do that? Thanks a lot in advance! NSArray *list = [NSArray arrayWithObjects:@"apple, animal, bat, ball", nil]; NSMutableDictionary *dict = [NSMutableDictionary dictionary]; for (NSString *word in list) {

Help parsing a nested JSON object

非 Y 不嫁゛ 提交于 2019-11-30 19:17:51
问题 I have the following JSON : { "meta": { "code": 200 }, "response": { "deals": [ { "id": 32373, "date_added": "2011-01-13 12:12:50", "end_date": "2011-01-14 10:00:00", "active": 1, "discount": { "raw": 71, "formatted": "71%" }, "price": { "raw": "85.00", "formatted": "$85" }, "value": { "raw": "300.00", "formatted": "$300" }, "purchased": 82, "left": null, "title": "$85 For $300 Babyface Facial At Park Avenue MedSpa", "yipit_title": "71% off Babyface Facial", "url": "http://yipit.com/aff/click

Removing nulls from a JSON structure recursively

时光毁灭记忆、已成空白 提交于 2019-11-30 17:51:31
问题 I'm frequently finding the need to cache data structures created by NSJSONSerialization to disk and as -writeToFile fails if there are nulls, I need a fix that works when the structure is unknown. This works, and direct mutation is allowed as the instances of NSMutableDictionary themselves are not being enumerated, but it feels a bit hacky. Is this totally fine or is it absolutely necessary to recreate a new tree and return that? - (void) removeNullsFromJSONTree:(id) branch { if ([branch