我从JSON获得响应,并将其存储在数组中,并且要将值存储{albumId albumName coverPhotoURL createdDate}
在Core Data中,请帮助我。
(
{
albumId = 1;
albumName = UAE;
coverPhotoURL = "http://1-dot-digiphoto-01.appspot.com/serve?blob-key=AMIfv95XeG-ii4aKZsUB5w-ClP0QUhJZa-o5BQRvdqArCCwg0Ueb13-wAfmyNHgaDdTaFS152_kXkJg5_9386zlfRCDc3fagW7Ekagdd6_VvJl6IscqNkyvVkXKYAqIRe-KqDMpjG-cW";
createdDate = "10-Jun-2010 06:11 PM";
description = "photos took in Dubai";
lastViewedDate = "10-Jun-2010 06:11 PM";
modifiedDate = "10-Jun-2010 06:11 PM";
numberOfPhotos = 10;
}
)
您需要创建NSManagedObject的子类并定义所有需要的字段
@interface AlbumInfo : NSManagedObject
@property (nonatomic, retain) NSNumber * albumId;
@property (nonatomic, retain) NSString * albumName;
@property (nonatomic, retain) NSString * coverPhotoURL;
@property (nonatomic, retain) NSDate * createdDate;
@end
那么您需要调用此代码
context = /* Get the NSManagedObject context */
AlbumInfo *item = [NSEntityDescription insertNewObjectForEntityForName:@"AlbumInfo" inManagedObjectContext:context];
item.albumId = @"some value from json";
/* ... so on ...*/
NSError *error = nil;
if (context != nil) {
if ([managedObjectContext hasChanges] && ![context save:&error]) {
// Replace this implementation with code to handle the error appropriately.
// abort() causes the application to generate a crash log and terminate. You should not use this function in a shipping application, although it may be useful during development.
NSLog(@"Unresolved error %@, %@", error, [error userInfo]);
}
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句