Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

moonman239

Cancelled
Original poster
Mar 27, 2009
1,541
32
Hello everyone,

In my Core Data model, I have an attribute that is of the NSData type. The data assigned to this attribute is supposed to represent a dictionary.

I can't use NSString's initWithData method. Nor can I use the JSON object serialization class.
 
Last edited:
Why you can't use this ?

Code:
NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData
options:kNilOptions error:&error];
 
Last edited by a moderator:
Why you can't use this ?

Code:
NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:responseData
options:kNilOptions error:&error];

Just wanted to add that JSONObjectWithData's return value is supposed to be of type NSString.

Quick internet search gives the following SO answer.

http://stackoverflow.com/questions/5513075/how-can-i-convert-nsdictionary-to-nsdata-and-vice-versa

The most popular answer does this using two lines of code. :)

Thank you!
 
Just wanted to add that JSONObjectWithData's return value is supposed to be of type NSString.

No it's not. The returned typename is id:
Code:
+ (id)JSONObjectWithData:(NSData *)data options:(NSJSONReadingOptions)opt error:(NSError **)error
The description says "The top level object is an NSArray or NSDictionary."
 
No it's not. The returned typename is id:
Code:
+ (id)JSONObjectWithData:(NSData *)data options:(NSJSONReadingOptions)opt error:(NSError **)error
The description says "The top level object is an NSArray or NSDictionary."

Oh, OK. I suppose the reason I got the warning is that I didn't get enough sleep last night.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.