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.");
}
}
}
上一篇:iOS开发之JSON解析


下一篇:eclipse java formater 配置详解