gpt4 book ai didi

Objective-C如何将xml转换为字符串?

转载 作者:行者123 更新时间:2023-12-03 17:44:00 25 4
gpt4 key购买 nike

这段代码有什么问题吗?它假设将 xml 数据转换为字符串并将其打印到日志中?但是它不打印任何内容!?

-(IBAction)request:(id)sender
{
NSURL *url = [NSURL URLWithString:@"http://api.twitter.com/1/statuses/public_timeline.xml"];
theRequest = [[NSMutableURLRequest alloc] initWithURL:url];
theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
receivedData=[[NSMutableData data] retain];

NSString *s = [[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding];
NSLog(@"%@", s);
[s release];

//parser = [[NSXMLParser alloc] initWithData:receivedData];
//[parser setDelegate:self];
//[parser parse];
}

还有想法吗?

提前致谢

最佳答案

receivedData=[[NSMutableData data] retain];

您正在初始化空数据,之后,url 连接和 url 请求将不再使用。初始化数据为空。

关于Objective-C如何将xml转换为字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4615256/

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