【发布时间】:2011-06-22 09:35:06
【问题描述】:
嗨,我是 iphone 开发新手
我正在使用 web 服务连接我获取 json 响应字符串的位置,我正在使用 JSONvalue 解析 json responsetring,我正在使用按钮在标签上显示解析的 json...
当我单击按钮时,解析后的 json 将显示在标签字段上..
我的问题是可以在 UI 中有一个文本字段、按钮和 webview 或 tableview..
当我在文本字段中输入特定方法时,因为 json 文件很大,然后按下按钮 shd 在 webview 或 tableview 上显示特定方法的内容..
这可能吗?如果是,那么如何实现?
谢谢你
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
[connection release];
NSString *responseString = [[NSString alloc] initWithData:dataWebService encoding:NSUTF8StringEncoding];
self.dataWebService = nil;
NSArray* latestLoans = [(NSDictionary*) [responseString JSONValue] objectForKey:@"loans"];
[responseString release];
NSDictionary* loan = [latestLoans objectAtIndex:0];
//fetch the data
NSNumber* fundedAmount = [loan objectForKey:@"funded_amount"];
NSNumber* loanAmount = [loan objectForKey:@"loan_amount"];
float outstandingAmount = [loanAmount floatValue] - [fundedAmount floatValue];
NSString* name = [loan objectForKey:@"name"];
NSString* country = [(NSDictionary*)[loan objectForKey:@"location"] objectForKey:@"country"];
//set the text to the label
label.numberOfLines = 0;
label.text = [NSString stringWithFormat:@"Latest loan: %@ \n \n country: %@ \n \n µamount $%.2f", name,country,outstandingAmount];
【问题讨论】:
-
您能否尝试重新表述您的问题?我真的不明白你的意思。
-
@Nayefc 实际上,目前我在 UI 中有一个按钮和一个标签,当我按下 Button 时,它会在 LABEL 中显示结果。即,它从 JSON 文件中获取并使用解析 json 显示在 LABEL 上。 .Actually我的要求是我在UI中有一个Textfield,button和一个webview......当我在TextField中输入一个字符串时,它会从JSon文件中搜索,例如上面代码中的“loans”......它的内容shd显示在 webview 中……你明白了吗?
标签: iphone objective-c ios xcode json