简体   繁体   English

如何处理与节点ID对应的响应对象?

[英]How do i deal with my response object which corresponds to node ids?

Edit wording.. 编辑措辞

I am using a 3rd party library called Drupal-IOS-SDk to connect my Drupal website with my under development IOS app. 我正在使用一个名为Drupal-IOS-SDk的第三方库将我的Drupal网站与正在开发的IOS应用程序连接起来。 I use a method to index nodes on my website and I am just wondering if anyone has any knowledge about how to deal with the response from my website. 我使用一种方法来索引我网站上的节点,我只是想知道是否有人对如何处理我的网站的响应有任何了解。 To give a little context if I run a similar bit of code to my index method (a getNode method) which works fine and I am able to access my response perfectly as shown below: 如果我运行与索引方法(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]);
 }];

This is the what gets printed by response object(I didnt include the whole thing but youll get the point): 这是响应对象打印的内容(我没有包括整个内容,但您会明白这一点):

    //printed statement for correctly working nodeGet method

{
changed = 1390534644;

comment = 0;

created = 1390534644;

data = "b:0;";

"ds_switch" = "";

"field_additional_pictures" =     (
);
"field_author" =     {
    und =

The above code gets node data and calling the "objectforkey" method on responseObject lets me access numbers or whatever else is stored in my responseObject. 上面的代码获取节点数据,并在responseObject上调用“ objectforkey”方法使我可以访问数字或其他存储在responseObject中的内容。 Where I have commented pull data from response object I get back the integer "1390534644" which correctly corresponds to the "changed" variable as you can see from the printed response above. 在我评论了来自响应对象的提取数据的地方,我得到了整数“ 1390534644”,该整数正确地对应于“更改的”变量,如您从上面的打印响应中所见。 The above section works fine. 上面的部分工作正常。 It is the next step where I get confused: 这是我感到困惑的下一步:

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

In this section I index all of the nodes and get fields from each instead of getting all of the information from only one node. 在本节中,我为所有节点建立索引并从每个节点获取字段,而不是仅从一个节点获取所有信息。 I get a response which shows things are working correctly thus far because the response has the correct info. 我得到了一个响应,该响应显示出到目前为止一切正常,因为该响应具有正确的信息。 I am confused though because I am not sure what my response object is exactly. 我很困惑,因为我不确定我的响应对象到底是什么。 It is a collection of nodes each with a "nid" and "uri" as shown from the index method responseObject below. 它是节点的集合,每个节点都有一个“ nid”和“ uri”,如下面的索引方法responseObject所示。 If I wanted to get the value "650" for example from my first "nid" in the below printed area how would I go about doing this? 例如,如果我想从下面打印区域的第一个“ nid”中获取值“ 650”,我将如何进行? I dont think I can call "objectForKey" as I did in the first working example because each node has a "nid". 我不认为我可以像在第一个工作示例中那样调用“ objectForKey”,因为每个节点都有一个“ nid”。 If I told my app to look for a key named nid it doesnt know which one to look for. 如果我告诉我的应用查找名为nid的密钥,则它不知道要寻找哪个密钥。 With no unique keys how can I access the number 650? 没有唯一键,如何访问数字650? I have printed my index method responseObject below so you can see what I am talking about. 我在下面打印了索引方法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";
},

It's been a few months since you asked this question, so I'm not sure if you're still looking for an answer, but in case anyone in the future needs it. 您问这个问题已经有几个月了,所以我不确定您是否还在寻找答案,但是万一将来有人需要它。

The responseObject is an array of NSDictionary objects. responseObject是NSDictionary对象的数组。 You can access the responseObject items just like an array and do whatever you need to with them depending on what you need the data for. 您可以像数组一样访问responseObject项目,并根据需要的数据来对它们进行任何处理。

For example: 例如:

NSArray *responseArray = responseObject;

for (NSDictionary *item in responseArray)

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 每当对应于该单元格的NSFetchedResultsController中的对象发生更改时,如何使单元格的外观更新? - How do I make what my cell looks like update each time there is a change to the object in NSFetchedResultsController that corresponds to the cell? 如何解析此json响应对象? - How do I parse this json response object? 我如何处理异步意大利面条代码? - How do I deal with asynchronous spaghetti code? 我如何处理Flurries的积累? - How do I deal with an accumulation of Flurries? 为什么每次更改单元格对应的对象的值时都会调用我的`configureCell:`方法? (但我不保存它。) - Why is my `configureCell:` method called every time I change the value of the object the cell corresponds to? (But I DON'T save it.) 我怎样才能准确地知道哪个物体导致我的撞车? - How can I exactly know which object caused my crash? 如何在Objective-C中测试对象是哪个类? - How do I test which class an object is in Objective-C? 如何正确初始化一个对象的变量实例? - How do I initialize a variable instance which is an object properly? 如何确定运行应用程序的路径? - How do I determine which path my application is run from? 如何检测用户使用的iOS设备? - How do I detect which iOS device my user is using?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM