Ferrakkem Bhuiyan
Ferrakkem Bhuiyan

Reputation: 2783

What is my mistake, trying to parsing json-data in objective c

I am new to objective-c. I'm trying to parse json-data but I'm failing. Would you kindly help to solve my problem:

#import <Foundation/Foundation.h>
int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSDictionary *jSonData = @{@"key" :@ "value"};

        NSData *jsonDicData =[NSJSONSerialization dataWithJSONObject:jSonData options:NSJSONWritingPrettyPrinted error:Nil];

        NSLog(@" %@",[[NSString alloc] initWithData:jsonDicData encoding:NSUTF32StringEncoding]);

        NSDictionary *decodeDict =[NSJSONSerialization JSONObjectWithData:jsonDicData options:0 error:Nil];

        assert([jSonData isEqual:decodeDict]);
    }
    return 0;
}

My output is this:

2015-04-28 18:04:58.183 Parse Json data[18599:38038]  (null)

Thanks in advance

Upvotes: 0

Views: 40

Answers (1)

jrturton
jrturton

Reputation: 119242

JSON is encoded using NSUTF8StringEncoding. Change that and you're fine.

Upvotes: 4

Related Questions