Hi
The time since Apple has provided JSONSerialisation things have became far more easier.
For my ease i have created 2 methods for JSON Conversion to-fro.
Hope someone finds it suitable too.
The time since Apple has provided JSONSerialisation things have became far more easier.
For my ease i have created 2 methods for JSON Conversion to-fro.
Hope someone finds it suitable too.
+ (NSString*)convertDictionaryToJSONString:(NSDictionary*)dict
{
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dict
options:NSJSONWritingPrettyPrinted
error:nil];
return [[NSString alloc] initWithData:jsonData
encoding:NSUTF8StringEncoding];
}
+ (NSDictionary*)convertJSONDataToDictionary:(NSData*)data
{
NSDictionary *parsedData = nil;
parsedData = [NSJSONSerialization JSONObjectWithData:data
options:NSJSONReadingMutableContainers
error:nil];
return parsedData;
}
No comments:
Post a Comment