nsdictionary

How do I deserialize a JSON string into an NSDictionary? (For iOS 5+)

安稳与你 提交于 2019-11-26 05:16:23
问题 In my iOS 5 app, I have an NSString that contains a JSON string. I would like to deserialize that JSON string representation into a native NSDictionary object. \"{\\\"password\\\" : \\\"1234\\\", \\\"user\\\" : \\\"andreas\\\"}\" I tried the following approach: NSDictionary *json = [NSJSONSerialization JSONObjectWithData:@\"{\\\"2\\\":\\\"3\\\"}\" options:NSJSONReadingMutableContainers error:&e]; But it throws the a runtime error. What am I doing wrong? -[__NSCFConstantString bytes]:

Best way to sort an NSArray of NSDictionary objects?

梦想的初衷 提交于 2019-11-26 03:50:15
问题 I\'m struggling with trying to sort an array of dictionaries. My dictionaries have a couple of values of interest, price, popularity etc. Any suggestions? 回答1: Use NSSortDescriptor like this.. NSSortDescriptor * descriptor = [[NSSortDescriptor alloc] initWithKey:@"interest" ascending:YES]; stories = [stories sortedArrayUsingDescriptors:@[descriptor]]; recent = [stories copy]; stories is the array you want to sort. recent is another mutable array which has sorted dictionary values. Change the

Using NSPredicate to filter an NSArray based on NSDictionary keys

半城伤御伤魂 提交于 2019-11-26 03:05:01
问题 I have an array of dictionaries. I want to filter the array based on a key. I tried this: NSPredicate *predicate = [NSPredicate predicateWithFormat:@\"(SPORT == %@)\", @\"Football\"]; NSArray *filteredArray = [data filteredArrayUsingPredicate:predicate]; This doesn\'t work, I get no results. I think I\'m doing something wrong. I know this is the method if \"SPORT\" was an ivar. I think it is probably different if it is a key. I haven\'t been able to find an example however. Thanks Update I

Swift - Stored values order is completely changed in Dictionary

╄→尐↘猪︶ㄣ 提交于 2019-11-26 02:38:56
问题 I tried to display datas which is in Dictionary format. Below, three attempts are there. First attempt, output order is completely changed. Second attempt, output order is same as input. But, in third attempt, I declared variable as NSDictionary. Exact output I received. Why this changes in Dictionary? Kindly guide me. I searched for Swift\'s Dictionary tag. But I couldn\'t found out. //First Attempt var dict : Dictionary = [\"name1\" : \"Loy\", \"name2\" : \"Roy\"] println(dict) //output:

Best practice? - Array/Dictionary as a Core Data Entity Attribute [closed]

我们两清 提交于 2019-11-26 02:15:56
问题 Closed . This question is opinion-based. It is not currently accepting answers. Want to improve this question? Update the question so it can be answered with facts and citations by editing this post. Closed 4 years ago . I am new to Core Data. I have noticed that collection types are not available as attribute types and would like to know what the most efficient way is of storing array/dictionary type data as an attribute (e.g. the elements that make up an address like street, city, etc. does

NSDictionary with ordered keys

蹲街弑〆低调 提交于 2019-11-26 00:37:53
问题 I have an NSDictionary (stored in a plist) that I\'m basically using as an associative array (strings as keys and values). I want to use the array of keys as part of my application, but I\'d like them to be in a specific order (not really an order that I can write an algorithm to sort them into). I could always store a separate array of the keys, but that seems kind of kludgey because I\'d always have to update the keys of the dictionary as well as the values of the array, and make sure they

How to use NSJSONSerialization

泄露秘密 提交于 2019-11-25 22:49:32
问题 I have a JSON string (from PHP\'s json_encode() that looks like this: [{\"id\": \"1\", \"name\":\"Aaa\"}, {\"id\": \"2\", \"name\":\"Bbb\"}] I want to parse this into some sort of data structure for my iPhone app. I guess the best thing for me would be to have an array of dictionaries, so the 0th element in the array is a dictionary with keys \"id\" => \"1\" and \"name\" => \"Aaa\" . I do not understand how the NSJSONSerialization stores the data though. Here is my code so far: NSError *e =