1

문구 편집 ..노드 ID에 해당하는 응답 객체를 어떻게 처리합니까?

드루팔 (Drupal-IOS-SDk)이라는 타사 라이브러리를 사용하여 Drupal 웹 사이트를 개발중인 IOS 앱과 연결합니다. 내 웹 사이트에서 노드를 인덱싱하는 방법을 사용하며 내 웹 사이트의 응답을 처리하는 방법에 대해 지식이있는 사람이 있는지 궁금합니다.

//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]); 
}]; 

이 무엇을 얻는 것입니다 : 내가 잘 작동 내 인덱스 방법 (A는 getNode 방법)에 코드의 유사한 비트를 실행하고 나는 완벽하게 내 대답에 액세스 할 수 있어요 경우 아래와 같이 약간의 컨텍스트를 부여하려면 응답 객체에 의해 인쇄 (나는 모든 것을 포함하지만 점을 알면 얻을 didnt가) :

//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. 내가 응답 객체로부터 데이터를 끌어와 주석을 달았다면 위의 인쇄 된 응답에서 알 수 있듯이 "changed"변수에 정확하게 해당하는 정수 "1390534644"가 반환됩니다. 위의 섹션은 잘 작동합니다. 그것은 다음 내가 혼란스러워 단계 : 노드의이 섹션 I 지수에서

//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]); 
        }]; 

모든 단 하나 개의 노드에서 모든 정보를 얻는 각 대신의 필드를 얻을. 응답에 올바른 정보가 있기 때문에 상황이 올바르게 작동하고 있음을 보여주는 응답이 표시됩니다. 나는 내 응답 객체가 정확히 무엇인지 확실하지 않기 때문에 혼란 스럽다. 아래의 index 메소드 responseObject에서 볼 수 있듯이 "nid"와 "uri"가있는 노드 모음입니다. 아래의 인쇄 영역에서 첫 번째 "nid"에서 "650"값을 얻고 싶다면 어떻게해야합니까? 각 노드에 "nid"가 있기 때문에 첫 번째 작업 예제에서했던 것처럼 "objectForKey"를 호출 할 수 없다고 생각합니다. 내 앱에 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"; 
}, 

답변

2

이 질문을하기 때문에 그것은 몇 개월되었습니다, 그래서 당신은 여전히 ​​답을 찾고 있는지 확실하지 않습니다 만, 미래의 경우 사람이 필요합니다.

responseObject는 NSDictionary 개체의 배열입니다. 배열과 마찬가지로 responseObject 항목에 액세스하여 데이터가 필요한 항목에 따라 필요한 모든 작업을 수행 할 수 있습니다. 예를 들어

:

NSArray *responseArray = responseObject; 

for (NSDictionary *item in responseArray) 

{ 
    // Do something with your item here 
    // For example: 
    NSString *uriStr = [item valueForKey:@"uri"]; 
}