我有一個REST API託管在我com域,其在接收到請求這樣www.mydomain.com/api/lists將返回格式數據的JSON如下所示RestKit NSFetchRequest塊爲孤立對象
[
{"list_id":"1","listName":"List Name 1"},
{"list_id":"2","listName":"List Name 2"},
{"list_id":"5","listName":"List Name 3"},
{"list_id":"7","listName":"List Name 4"},
{"list_id":"8","listName":"List Name 5"},
{"list_id":"11","listName":"List Name 6"},
{"list_id":"12","listName":"List Name 7"}
]
的缺失
現在我在我的RKObjectManger加入NSFetchRequest座,檢查使用此代碼
[objectManager addFetchRequestBlock:^NSFetchRequest *(NSURL *URL) {
RKPathMatcher *pathMatcher = [RKPathMatcher pathMatcherWithPattern:@"/api/lists"];
NSDictionary *argsDict = nil;
BOOL match = [pathMatcher matchesPath:[URL relativePath] tokenizeQueryStrings:NO parsedArguments:&argsDict];
NSString *listID;
if (match)
{
listID = [argsDict objectForKey:@"list_id"];
NSLog(@"The listID is %@",listID);
NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
NSEntityDescription *entity = [NSEntityDescription entityForName:@"List"
inManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext];
[fetchRequest setEntity:entity];
fetchRequest.predicate = [NSPredicate predicateWithFormat:@"listID = %@", @([listID integerValue])];
return fetchRequest;
}
return nil;
}];
但我listID = [argsDict objectForKey:@"list_id"];
返回nil孤立的對象,儘管事實上從網絡返回的JSON具有「LIST_ID」在裏面。請指導我這裏出了什麼問題。因爲在路徑模式/api/lists
沒有list_id
參數
listID = [argsDict objectForKey:@"list_id"];
NSLog(@"The listID is %@",listID);
:
也我的詞典argsDict是空的。任何人都可以告訴我爲什麼會發生這種情況? – Umair
你的'json'響應是'Array'。 – Akhilrajtr