Automatic Coder - 根據 JSON 自動生成對應的 Objective-C 處理代碼

jopen 12年前發布 | 42K 次閱讀 JSON iOS開發 移動開發

Automatic Coder 可根據 JSON 字符串自動生成對應的 Objective-C 處理代碼。

示例代碼:

   NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://zxapi.sinaapp.com"]];
    NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
    NSDictionary *json = [data objectFromJSONData];

    //init object
    Person *person = [[Person alloc] initWithJson:json];
    NSLog(@"%@",person.name);                //http://zhangxi.me
    NSLog(@"%@",person.male?@"男":@"女");     //男
    NSLog(@"%ld",person.girlFriends.count);   //3


    //write to file
    BOOL result = [NSKeyedArchiver archiveRootObject:person toFile:@"./person.data"];
    NSLog(@"%@",result?@"success":@"failure");   //success


    //read from file
    Person *thePerson = [NSKeyedUnarchiver unarchiveObjectWithFile:@"./person.data"];

    NSLog(@"%@",thePerson.name);                //http://zhangxi.me
    NSLog(@"%@",thePerson.male?@"男":@"女");     //男
    NSLog(@"%ld",thePerson.girlFriends.count);   ///3

項目主頁:http://www.baiduhome.net/lib/view/home/1347433841897

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!