首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >TFHpple返回null作为响应

TFHpple返回null作为响应
EN

Stack Overflow用户
提问于 2012-04-23 19:38:12
回答 1查看 513关注 0票数 0

我正在尝试在我的项目中使用TFHpple,下面是代码...它很容易理解:

代码语言:javascript
复制
- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    NSURL *url = [NSURL URLWithString:@"http://v1.myurl.com/somemethod"];
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request setDelegate:self];
    [request startAsynchronous];
}

- (void)viewDidUnload
{
    [self setGpMapView:nil];
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    return YES;
}

- (void)requestFinished:(ASIHTTPRequest *)request
{
    // Use when fetching text data
    NSString *responseString = [request responseString];

    // Use when fetching binary data
    NSData *responseData = [request responseData];
    TFHpple *doc = [[TFHpple alloc] initWithXMLData:responseData];
    NSArray *elements = [doc searchWithXPathQuery:@"/entry"];
    NSLog(@"count: %@",[elements count]);

}

- (void)requestFailed:(ASIHTTPRequest *)request
{
    NSError *error = [request error];
}

其间我还使用了asihttp库来进行http请求调用。我在控制台中得到了null,我已经检查了xml again..and,我知道这个标签肯定在那里。有什么办法吗?

编辑-1

下面是xml模式:

代码语言:javascript
复制
<feed xmlns:s="http://syndication.nhschoices.nhs.uk/services" xmlns="http://www.w3.org/2005/Atom">
<title type="text">
NHS Choices - GP Practices Near Location - richmond - Within 50km
</title>
<id>
http://v1.syndication.nhschoices.nhs.uk/organisations/gppractices/location?range=50&northing=174900&easting=517900
</id>
<rights type="text">© Crown Copyright 2009</rights>
<updated>2012-04-24T11:54:04+01:00</updated>
<category term="Search"/>
<logo>
http://www.nhs.uk/nhscwebservices/documents/logo1.jpg
</logo>
<author>
<name>NHS Choices</name>
<uri>http://www.nhs.uk</uri>
<email>webservices@nhschoices.nhs.uk</email>
</author>
<link rel="self" type="application/xml" title="NHS Choices - GP Practices Near Location - richmond - Within 50km" href="http://v1.syndication.nhschoices.nhs.uk/organisations/gppractices/location?apikey=YAHUGHET&range=50&northing=174900&easting=517900&name=richmond"/>
<link rel="first" type="application/xml" title="first" length="1000" href="http://v1.syndication.nhschoices.nhs.uk/organisations/gppractices/location?apikey=YAHUGHET&range=50&northing=174900&easting=517900&name=richmond&page=1"/>
<link rel="next" type="application/xml" title="next" length="1000" href="http://v1.syndication.nhschoices.nhs.uk/organisations/gppractices/location?apikey=YAHUGHET&range=50&northing=174900&easting=517900&name=richmond&page=2"/>
<link rel="last" type="application/xml" title="last" length="1000" href="http://v1.syndication.nhschoices.nhs.uk/organisations/gppractices/location?apikey=YAHUGHET&range=50&northing=174900&easting=517900&name=richmond&page=10"/>
<link rel="alternate" title="NHS Choices - Find and choose services - GP Practices" href="http://www.nhs.uk/ServiceDirectories/pages/ServiceSearch.aspx?ServiceType=GP"/>
<s:SearchCoords>174900,517900</s:SearchCoords>
<entry>
<id>
http://v1.syndication.nhschoices.nhs.uk/organisations/gppractices/32248
</id>
<title type="text">Sayer A</title>
<updated>2012-04-24T10:54:04Z</updated>
<link rel="self" title="Sayer A" href="http://v1.syndication.nhschoices.nhs.uk/organisations/gppractices/32248?apikey=YAHUGHET"/>
<link rel="alternate" title="Sayer A" href="http://www.nhs.uk/ServiceDirectories/Pages/GP.aspx?pid=15F37AEF-EC5B-4A90-9E72-269ADEB39629"/>
<content type="application/xml">
<s:organisationSummary>
<s:name>Sayer A</s:name>
<s:address>
<s:addressLine>The Richmond Green Medical Cen</s:addressLine>
<s:addressLine>19 The Green</s:addressLine>
<s:addressLine>Richmond</s:addressLine>
<s:addressLine>Surrey</s:addressLine>
<s:postcode>TW91PX</s:postcode>
</s:address>
<s:contact type="General">
<s:telephone>020 83327515</s:telephone>
</s:contact>
<s:geographicCoordinates>
<s:northing>174900</s:northing>
<s:easting>517800</s:easting>
<s:longitude>-0.305512266736965</s:longitude>
<s:latitude>51.4608026642546</s:latitude>
</s:geographicCoordinates>
<s:Distance>0.1</s:Distance>
</s:organisationSummary>
</content>
</entry>
<entry>
EN

回答 1

Stack Overflow用户

发布于 2012-04-24 20:36:28

好的。显然,你的根元素是<feed>,里面有一些<entry>元素。因此,您必须更改这一行(请注意两个'/')才能捕获它们。此外,如果您记录您的响应,以确保您为解析器提供了正确的xml,这也会很有帮助:

代码语言:javascript
复制
NSArray *elements = [doc searchWithXPathQuery:@"//entry"];
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/10279782

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档