无论如何加载带有来自网页的文本的UILabel?

时间:2011-03-30 00:20:16

标签: html ios iphone cocoa-touch uilabel

无论如何加载带有网页文字的UILabel?如果我定义了一个网页,那么我可以从页面中删除文本吗?

如果在页面的来源中说“9.5000 / 9.5009”,我可以使用“9.5000 / 9.5009”并将其作为标签的文本,即使该数字发生更改,也可以通过使用宣布“费率”?或者我错误地将其声明为“费率”。

我可以使用以下代码:

#define kLatestKivaLoansURL @"http://www.roblox.com/Marketplace/TradeCurrency.aspx"

NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSArray* latestLoans = [(NSDictionary*)[responseString JSONValue] objectForKey:@"Rate"];
NSDictionary* loan = [latestLoans objectAtIndex:0];
NSString* rate = [loan objectForKey:@"Rate"];
label.text = [NSString stringWithFormat:@"%i",rate];

如果没有页面输出JSON,有没有办法做到这一点?

1 个答案:

答案 0 :(得分:0)

NSURL *url = [NSURL URLWithString:@"http://www.domain.com/rateScript.php"];
NSString *response = [[NSString alloc] initWithContentsOfURL:url];
label.text=response;
[response release];

使用以下脚本:

<?php
$ratefile=file_get_contents("http://www.roblox.com/Marketplace/TradeCurrency.aspx");
$position=0;
$position=strpos($ratefile, '"Rate"',$position)+7;
$start=strpos($ratefile, '"Rate"',$position)+7;
$end=strpos($ratefile, '<',$start+1);
echo substr($ratefile,$start,$end-$start);
?>