0
我想了解restkit 0.22。我从不同的博客和youtubes一些教程。我结束了混合代码。RestKit与我的JSON数据不工作
任何人都可以请帮助我,我真的需要它为我的项目工作。
我创建核心数据模型与实体Songs.xcdatamodeld
我有一个来自于我的MySQL数据库一个JSON:
在AppDelegate.m[{"SongID":"1","SongTitle":"Song1","PerformerName":"Performer1","SongURL":"http://mysite/mysongs/1.mp3","PerformerPic":"PerfPic1.png"},
{"SongID":"2","SongTitle":"Song2","PerformerName":"Performer2","SongURL":"http://mysite/mysongs/2.mp3","PerformerPic":"PerfPic2.png"},
{"SongID":"3","SongTitle":"Song3","PerformerName":"Performer3","SongURL":"http://mysite/mysongs/3.mp3","PerformerPic":"PerfPic3.png"}]
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
RKObjectManager *objectManager = [RKObjectManager managerWithBaseURL:[NSURL URLWithString:http://mysite]];
NSURL *modelURL = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"Songs" ofType:@"momd"]];
//Initialize managed object store
NSManagedObjectModel *managedObjectModel = [[[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL ] mutableCopy];
RKManagedObjectStore *managedObjectStore = [[RKManagedObjectStore alloc] initWithManagedObjectModel:managedObjectModel];
objectManager.managedObjectStore = managedObjectStore;
[RKObjectManager sharedManager].requestSerializationMIMEType = RKMIMETypeJSON;
[RKMIMETypeSerialization registeredMIMETypes];
[objectManager setAcceptHeaderWithMIMEType:@"application/json"];
RKEntityMapping* mapping = [RKEntityMapping mappingForEntityForName:@"Songs"
inManagedObjectStore:[RKObjectManager sharedManager].managedObjectStore];
mapping.identificationAttributes = @[@"songID"];
[mapping addAttributeMappingsFromDictionary:@{@"id" : @"SongID",
@"songTitle" : @"SongTitle",
@"performerName" : @"PerformerName",
@"songURL" : @"SongURL",
@"performerPic" : @"PerformerPic"}];
return YES;
}
在TableView中控制器
:
- (void)viewDidLoad
{
[super viewDidLoad];
[RKObjectManager.sharedManager getObjectsAtPath:@"/api.php"
parameters:nil
success:^(RKObjectRequestOperation *operation, RKMappingResult *mappingResult)
{
self.Songs = [mappingResult array];
NSLog(@"It Worked: %@", self.Songs);
} failure:^(RKObjectRequestOperation *operation, NSError *error) {
NSLog(@"It Failed: %@", error);
}];
}
这是我得到的错误:
GET 'http://mysite/api.php' (200 OK/0 objects) [request=3.5566s mapping=0.0000s
total=3.5627s]: Error Domain=org.restkit.RestKit.ErrorDomain Code=1001
"No response descriptors match the response loaded." UserInfo=0xb5920b0
{NSErrorFailingURLStringKey=http://mysite/api.php, NSLocalizedFailureReason=A 200
response was loaded from the URL 'http://mysite/api.php', which failed to match all (0)
response descriptors:, NSLocalizedDescription=No response descriptors match the response
loaded., keyPath=null, NSErrorFailingURLKey=http://mysite/api.php,
NSUnderlyingError=0xb5921b0 "No mappable object representations were found at the key
paths searched."}
谢谢@Wain的回答,请您向我解释一下,在我的情况下,'回复描述符'是什么。 –