开发者

How to get burried "nodeContent" in an array

开发者 https://www.devze.com 2023-03-11 00:08 出处:网络
HI all, I have spent a couple hours on SO trying to get this solved. Long story short I am trying to get the value from a nodeContent in an array. When I have a breakpoint and \"print description\" of

HI all, I have spent a couple hours on SO trying to get this solved. Long story short I am trying to get the value from a nodeContent in an array. When I have a breakpoint and "print description" of an array this is what its spits out. My question is, how do I get the content of the burried "nodeContent" listed below? I would like to get this back in a string if possible?

NSArray Printout to console:

{
    nodeAttributeArray =     (
                {
            attributeName = class;
            nodeContent = g;
        }
    );
    nodeChildArray =     (
                {
            nodeAttributeArray =             (
                                {
                    attributeName = href;
                    nodeContent = "/site.aspx?s=23RBHJz4%2bck%3";
                }
            );
 开发者_如何学运维           nodeChildArray =             (
                                {
                    nodeContent = update;
                    nodeName = div;
                }
            );
            nodeContent = "3.49"; //THIS IS THE VALUE I WANT
            nodeName = a;
        }
    );
    nodeContent = "";
    nodeName = th;
}

Can I get it back as a string ?

NSString * value = [code]??

I would really appreciate any help!


You can modify TFHppleElement to return the children objects.

in TFHppleElement.h:

@interface TFHppleElement : NSObject
[..]

- (NSArray*)children
@end

in TFHppleElement.m:

NSString * const TFHppleNodeChildArrayKey     = @"nodeChildArray";

@implementation TFHppleElement
[..]
- (NSArray*)children {
    [node objectForKey:TFHppleNodeChildArrayKey];
}
[..]
@end

So now you can get it like this,

NSString *value = [[[object children] objectAtIndex:0] content];

Original Answer

The printout suggests that it is a dictionary object based on the curly braces. You might want to look at this. For this case, you should be able to get your value using,

NSString *value = [[object valueForKeyPath:@"nodeChildArray.nodeContent"] objectAtIndex:0];
0

精彩评论

暂无评论...
验证码 换一张
取 消