編輯措辭..我如何處理與節點ID相對應的響應對象?
我使用名爲Drupal-IOS-SDk的第三方庫將我的Drupal網站與我的開發IOS應用程序連接起來。我使用一種方法來索引我網站上的節點,我只是想知道是否有人知道如何處理來自我網站的響應。給一點背景下,如果我運行的代碼,類似位的正常工作我的索引方法(getNode方法),我能夠完美地訪問我的迴應如下圖所示:
//code for correctly working nodeGet method
NSMutableDictionary *nodeData = [NSMutableDictionary new];
[nodeData setValue:@"650" forKey:@"nid"];
[DIOSNode nodeGet:nodeData success:^(AFHTTPRequestOperation *operation, id responseObject) {
//print out responseObject
//NSLog(@"%@", responseObject);
//pull data from the responseObject
NSInteger testNumber = [responseObject objectForKey:@"changed"];
NSLog(@"%ld", (long)testNumber);
} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//we failed, uh-oh lets error log this.
NSLog(@"%@, %@", [error localizedDescription], [operation responseString]);
}];
這是什麼變通過響應對象印刷(我沒有包括整個的事情,但你會得到點):
//printed statement for correctly working nodeGet method
{
changed = 1390534644;
comment = 0;
created = 1390534644;
data = "b:0;";
"ds_switch" = "";
"field_additional_pictures" = (
);
"field_author" = {
und =
上面的代碼獲取節點數據,並呼籲responseObject的「objectforkey」的方法讓我的接入號碼或其他任何存儲在我的responseObject。如果我已經評論了從響應對象中提取數據,我可以從上面的打印響應中看到正確對應於「已更改」變量的整數「1390534644」。上面的部分工作正常。這是下一個步驟,我感到困惑:
//code for index method that is in question
NSMutableDictionary *paramsDictionary = [NSMutableDictionary new];
[paramsDictionary setValue:@"books_e_books_other_books" forKey:@"type"];
[DIOSNode nodeIndexWithPage:@"0" fields:@"nid" parameters:paramsDictionary pageSize:@"20"
success:^(AFHTTPRequestOperation *operation, id responseObject) {
//print response object
NSLog(@"%@", responseObject);
NSLog(@"GREAT SUCCESS");
//HERE IS MY PROBLEM!!!
//what do I do with response object?
}
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//code
NSLog(@"Oh no failed when trying to get the index");
NSLog(@"%@, %@", [error localizedDescription], [operation responseString]);
}];
在這一節中,我所有索引節點和每個,而不是讓讓所有的信息,從只有一個節點的領域。我得到了一個響應,顯示事情到目前爲止正確工作,因爲響應具有正確的信息。我很困惑,因爲我不確定我的回答對象是什麼。它是一個節點集合,每個節點都有一個「nid」和「uri」,如下面的索引方法responseObject所示。如果我想在下面的打印區域中從我的第一個「nid」中獲得值「650」,我該如何去做這件事?我不認爲我可以像第一個工作示例中那樣調用「objectForKey」,因爲每個節點都有一個「nid」。如果我告訴我的應用程序尋找一個名爲nid的密鑰,它不知道要尋找哪一個。沒有唯一的密鑰,我怎樣才能訪問650號碼?我已經在下面打印了我的索引方法responseObject,所以你可以看到我在說什麼。
//printed statement from index method, this is what i am confused about, there are no unique keys how do I access the value 650 or the first nid
{
nid = 650;
uri = "http://www.domain.com/domain_endpoint/node/650";
},
{
nid = 649;
uri = "http://www.domain.com/domain_endpoint/node/649";
},
{
nid = 647;
uri = "http://www.domain.com/domain_endpoint/node/647";
},