gpt4 book ai didi

iphone - 在 HTTP 响应中获取 XML 并读取它

转载 作者:行者123 更新时间:2023-11-29 13:40:54 26 4
gpt4 key购买 nike

我有以下方法,我还有另一种方法可以调用此方法,但还没有成功。

- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict{

if ([elementName isEqualToString:@"isphone-config"]) {
Pusername = [attributeDict valueForKey:@"authentication_username"];
Ppassword = [attributeDict valueForKey:@"authentication_password"];
Pidentity = [attributeDict valueForKey:@"sip_identity"];
Pdomain = [attributeDict valueForKey:@"domain"];
Pprotocol = [attributeDict valueForKey:@"protocol"];
Pudpport = [attributeDict valueForKey:@"registrar_port"];
Ptcpport = [attributeDict valueForKey:@"listening_port"];

NSLog(@"Title: %@, ID: %@", Pusername, Ppassword);
}
}
}

我通过以下方法调用它..

NSString* username = [[NSUserDefaults standardUserDefaults] stringForKey:@"username_preference"];
NSString* accountPassword = [[NSUserDefaults standardUserDefaults] stringForKey:@"password_preference"];
NSString* urlString = [NSString stringWithFormat:@"https://%@:%@@test.com/test.php",username,accountPassword];
NSURLRequest* request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];

parser = [[NSXMLParser alloc] initWithData: response];

NSLog(@"at parser %@", parser);

[parser setDelegate:self];

我在调用解析器的代码的最后一行遇到问题。我假设这一行将调用方法解析器,如果我错了请纠正我。我不知道我必须导入、包含或实现哪些文件、接口(interface)和类。

最佳答案

使用 NSXMLParser 进行 XML 解析要困难得多,查看 Apple 的示例“earthquakes”。

相反,我建议您使用另一个 XML 解析器。例如,this one :

Also, good article about how to choose parser.

http://www.raywenderlich.com/725/how-to-read-and-write-xml-documents-with-gdataxml

关于iphone - 在 HTTP 响应中获取 XML 并读取它,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9175280/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com