JsonParser

来源:互联网 发布:初学者吉他品牌知乎 编辑:程序博客网 时间:2024/06/16 18:16

[

    {

    "novelname":"西游记",

    "novelauthor":"吴承恩",

    "novelpage":100000

    },

 {

 "novelname":"水浒传",

 "novelauthor":"施耐庵",

 "novelpage":100000

 },

 {

 "novelname":"还珠格格",

 "novelauthor":"琼瑶",

 "novelpage":100000

 },

 ]



#import "ViewController.h"


@interface ViewController ()


@end


@implementation ViewController


- (void)awakeFromNib//storyboard的时候,用这个初始化

{


}


- (void)viewDidLoad {

    [superviewDidLoad];

    // Do any additional setup after loading the view, typically from a nib.

    

    [selfparserJson];

    

}

- (void)parserJson

{

    NSString *path = [[NSBundlemainBundle] pathForResource:@"Novel"ofType:@"json"];

    NSData *data = [[NSDataalloc] initWithContentsOfFile:path];

    NSArray *array = [NSJSONSerializationJSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];

   NSLog(@"%@",array);

    

    //把数字转换成字符串

   NSNumber *num = [NSNumbernumberWithInt:100];

   NSString *str = [NSStringstringWithFormat:@"%@",num];

    

    

}



0 0
原创粉丝点击