如何在数组中隐藏“节点内容”

时间:2011-06-05 07:21:15

标签: iphone ios4 iphone-sdk-3.0

大家好,我花了几个小时才试图解决这个问题。长话短说我试图从数组中的nodeContent获取值。当我有一个断点和一个数组的“打印描述”时,这就是它吐出来的东西。我的问题是,如何获得下面列出的“nodeContent”的内容?如果可能的话,我想把它放回一个字符串中?

NSArray打印输出到控制台:

{
    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;
}

我可以把它作为字符串取回来吗?

NSString * value = [code]??

我真的很感激任何帮助!

1 个答案:

答案 0 :(得分:1)

您可以修改TFHppleElement以返回子对象。

TFHppleElement.h中的

@interface TFHppleElement : NSObject
[..]

- (NSArray*)children
@end
TFHppleElement.m中的

NSString * const TFHppleNodeChildArrayKey     = @"nodeChildArray";

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

所以现在你可以这样做,

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

原始答案

打印输出表明它是一个基于花括号的字典对象。您可能希望查看this。对于这种情况,您应该能够使用

来获取您的价值
NSString *value = [[object valueForKeyPath:@"nodeChildArray.nodeContent"] objectAtIndex:0];