Converting NSString to NSDictionary / JSON

I believe you are misinterpreting the JSON format for key values. You should store your string as NSString *jsonString = @”{\”ID\”:{\”Content\”:268,\”type\”:\”text\”},\”ContractTemplateID\”:{\”Content\”:65,\”type\”:\”text\”}}”; NSData *data = [jsonString dataUsingEncoding:NSUTF8StringEncoding]; id json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; Now if you do following NSLog statement NSLog(@”%@”,[json objectForKey:@”ID”]); Result would be another NSDictionary. { Content = 268; type = text; }

Using NSPredicate to filter an NSArray based on NSDictionary keys

It should work – as long as the data variable is actually an array containing a dictionary with the key SPORT NSArray *data = [NSArray arrayWithObject:[NSMutableDictionary dictionaryWithObject:@”foo” forKey:@”BAR”]]; NSArray *filtered = [data filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@”(BAR == %@)”, @”foo”]]; Filtered in this case contains the dictionary. (the %@ does not have to be quoted, this is done … Read more

How to add to an NSDictionary

A mutable dictionary can be changed, i.e. you can add and remove objects. An immutable is fixed once it is created. create and add: NSMutableDictionary *dict = [[NSMutableDictionary alloc]initWithCapacity:10]; [dict setObject:[NSNumber numberWithInt:42] forKey:@”A cool number”]; and retrieve: int myNumber = [[dict objectForKey:@”A cool number”] intValue];

NSDictionary – Need to check whether dictionary contains key-value pair or not

Just ask it for the objectForKey:@”b”. If it returns nil, no object is set at that key. if ([xyz objectForKey:@”b”]) { NSLog(@”There’s an object set for key @\”b\”!”); } else { NSLog(@”No object set for key @\”b\””); } Edit: As to your edited second question, it’s simply NSUInteger mCount = [xyz count];. Both of these … Read more

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

It looks like you are passing an NSString parameter where you should be passing an NSData parameter: NSError *jsonError; NSData *objectData = [@”{\”2\”:\”3\”}” dataUsingEncoding:NSUTF8StringEncoding]; NSDictionary *json = [NSJSONSerialization JSONObjectWithData:objectData options:NSJSONReadingMutableContainers error:&jsonError];

How to use NSJSONSerialization

Your root json object is not a dictionary but an array: [{“id”: “1”, “name”:”Aaa”}, {“id”: “2”, “name”:”Bbb”}] This might give you a clear picture of how to handle it: NSError *e = nil; NSArray *jsonArray = [NSJSONSerialization JSONObjectWithData: data options: NSJSONReadingMutableContainers error: &e]; if (!jsonArray) { NSLog(@”Error parsing JSON: %@”, e); } else { for(NSDictionary … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)