Iphone 如何在webview中从json responseString获取特定方法
我有一个文本字段和按钮,下面还有一个网络视图 当我在文本字段中输入字符串并按下搜索按钮时,整个JSON响应字符串将显示在Iphone 如何在webview中从json responseString获取特定方法,iphone,objective-c,ios,xcode,json,Iphone,Objective C,Ios,Xcode,Json,我有一个文本字段和按钮,下面还有一个网络视图 当我在文本字段中输入字符串并按下搜索按钮时,整个JSON响应字符串将显示在UIWebview实例中 因此,我的要求是显示一个与textfield中输入的字符串匹配的特定方法 即使我在文本字段中输入任何字符串,当我按下搜索按钮时,它也会在webview中显示所有内容 是否可以从responseString获取特定方法 建议需要进行的更改 .h文件 IBOutlet UITextField *searchtextField; UIWeb
UIWebview
实例中
因此,我的要求是显示一个与textfield中输入的字符串匹配的特定方法
即使我在文本字段中输入任何字符串,当我按下搜索按钮时,它也会在webview中显示所有内容
是否可以从responseString获取特定方法
建议需要进行的更改
.h文件
IBOutlet UITextField *searchtextField;
UIWebView *webView;
}
-(IBAction)search;
@property (nonatomic, retain) UIWebView *webView;
-(IBAction)search
{
NSString *searchString=searchtextField.text;
NSString *urlAddress = [NSString stringWithFormat:@"http://api.kivaws.org/v1/loans/search.json?status=fundraising",searchString];
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
}
NSString *searchString=searchtextField.text;
NSString *urlAddress = [NSString stringWithFormat:@"http://api.kivaws.org/v1/loans/search.json?status=%@",searchString];
.m文件
IBOutlet UITextField *searchtextField;
UIWebView *webView;
}
-(IBAction)search;
@property (nonatomic, retain) UIWebView *webView;
-(IBAction)search
{
NSString *searchString=searchtextField.text;
NSString *urlAddress = [NSString stringWithFormat:@"http://api.kivaws.org/v1/loans/search.json?status=fundraising",searchString];
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
}
NSString *searchString=searchtextField.text;
NSString *urlAddress = [NSString stringWithFormat:@"http://api.kivaws.org/v1/loans/search.json?status=%@",searchString];
只需将
%@
放在searchString
要添加的位置…这一切都是关于您的,因为我不知道您要添加到哪里
示例
IBOutlet UITextField *searchtextField;
UIWebView *webView;
}
-(IBAction)search;
@property (nonatomic, retain) UIWebView *webView;
-(IBAction)search
{
NSString *searchString=searchtextField.text;
NSString *urlAddress = [NSString stringWithFormat:@"http://api.kivaws.org/v1/loans/search.json?status=fundraising",searchString];
NSURL *url = [NSURL URLWithString:urlAddress];
NSURLRequest *requestObj = [NSURLRequest requestWithURL:url];
[webView loadRequest:requestObj];
}
NSString *searchString=searchtextField.text;
NSString *urlAddress = [NSString stringWithFormat:@"http://api.kivaws.org/v1/loans/search.json?status=%@",searchString];
试一试….在代码NSString*URLADDESS=[NSString stringWithFormat:@“urlAddress stringWithFormat中没有任何%@格式,因此您可以添加searchStringya。url是api,输出格式是JSon。那么,我在代码中做了哪些更改?我说,在这段代码中,searchString的用途是什么,因为您在该代码中的任何地方都没有使用searchString Ex NSString*urlAddress=[NSString stringWithFormat:@“例如,这是google api..所以我无法准确地定位这是您希望将SearchStringWithFormat放置在的位置:@“这对谷歌有效。但是如果我把json响应的特定url放在上面,它就不会了。你想做什么呢?请弄清楚,在得到searchString后告诉我,并弄清楚你想从这里添加SearchStrings的地方,你会得到search.json文件