Thursday, July 24, 2014

Convert NSString to NSMutableDictionary


//JsonToDictionary method
-(NSMutableDictionary *)JsontoDictionary:(NSString*)jsonString {
    
    jsonData = [jsonString dataUsingEncoding:NSUTF32BigEndianStringEncoding];
    
    jsonDeserializer = [CJSONDeserializer deserializer];  // Third party JSON serialization
    NSError *error =nil;
    
    NSMutableDictionary *resultsDictionarytemp = [jsonDeserializer deserializeAsDictionary:jsonData error:&error];
    
    if (error != nil) {
        
        UIAlertView *errorAlertView = [[UIAlertView alloc] initWithTitle:@"Error" message:[error    localizedDescriptiondelegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
        
        [errorAlertView show];
    }
    
    return resultsDictionarytemp;

}


//Invoke method
NSMutableDictionary  *json = [self JsontoDictionary:strFileContent];

No comments:

Post a Comment