从远程XML文件解析元素之后,我在NSArray中获得了元素列表及其值。由于数组包含更多这样的元素和值,

success; products=<AGSProducts 0x7189020; name='category1';imageIdentifier='1'; imageUrlString='http://myimage.com/images/img1.png'; subProducts=>

我需要从此NSArrray获取imageUrlString。如何从这些数组中单独获取此特定的imageUrlString。

MyViewController
@property(nonatomic,strong) NSMutableArray *xmlProductsResults;

[super viewDidLoad];
NSURL *url = [NSURL URLWithString:@"http://myxml.com/Category.xml"];
EGSParser *parser = [[EGSParser alloc] init];
if ([parser loadXMLByURL:url]){
  self.xmlProductsResults = parser.products;
  NSArray *myArray = [_xmlProductsResults objectAtIndex:0];
  NSLog(@"success; products=%@", myArray);
}

请给我一个主意

最佳答案

希望这可以帮助。

编辑2

NSString *string = [myArray description];
NSString *url = nil;
NSScanner *parser = [NSScanner scannerWithString:string];
[parser scanUpToString:@"imageUrlString" intoString:nil];

if (![parser isAtEnd]) {
    [parser scanUpToString:@"=" intoString:nil];
    NSCharacterSet *charset = [NSCharacterSet characterSetWithCharactersInString:@"\"'"];
    [parser scanUpToCharactersFromSet:charset intoString:nil];
    [parser scanCharactersFromSet:charset intoString:nil];
    [parser scanUpToCharactersFromSet:charset intoString:&url];

}

NSLog(@"URL: %@", url);

关于ios - 如何从NSArray获取imageUrlString,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14998194/

10-10 20:41