iOS SDK原生JSON解析

- (IBAction)touchReadButton:(id)sender 
{          
        NSData *jsonData = [[NSData alloc]    initWithContentsOfFile:JSON_PATH];    
        NSError *error = nil;    
        id jsonObject = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingAllowFragments error:&error;];         
        if (jsonObject != nil && error == nil)
          {        
               NSLog(@"Successfully deserialized...");        
               if ([jsonObject isKindOfClass:[NSDictionary class]])
                {             
                    NSDictionary *deserializedDictionary = (NSDictionary *)    jsonObject;           
                  NSLog(@"Dersialized JSON Dictionary = %@", deserializedDictionary);         
                }
             else if([jsonObject isKindOfClass:[NSArray class]])
            {             
                NSArray *deserializedArray = (NSArray *)jsonObject;                     
                NSLog(@"Dersialized JSON Array = %@", deserializedArray);         
            }
      
else {
           NSLog(
@"An error happened while deserializing the JSON data.");
} } }

 

posted @ 2013-12-16 14:57  菜鸟程序猿  阅读(345)  评论(0编辑  收藏  举报