2011-06-22 24 views
1

我在下面有一個文本字段和按鈕以及一個webview。如何在webview中從json responseString獲取特定方法

當我在文本字段中輸入字符串並按搜索按鈕時,整個JSON響應字符串顯示在UIWebview實例中。

所以我的要求是顯示一個特定的方法,匹配在文本字段中輸入的字符串。

即使我在文本字段中輸入任何字符串時,當我按下搜索按鈕時,它顯示webview中的所有內容。

是否可以從responseString中獲取特定的方法?

建議需要完成的更改。

.h文件中

IBOutlet UITextField *searchtextField; 

    UIWebView *webView; 
} 

-(IBAction)search; 

@property (nonatomic, retain) UIWebView *webView; 

.m文件

-(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]; 
} 
+1

其中是ü在此代碼的NSString * urlAddress = [NSString的stringWithFormat加入searchString的在urlAddress:@「http://api.kivaws.org/ ?V1 /貸款/ search.json狀態=籌款」,搜索字符串]; –

+0

urlAddress中沒有任何%@格式stringWithFormat通過你可以添加搜索字符串 –

+0

雅是url是api和輸出格式是在JSon..so wat改變我shd在代碼中作出? – Abhilash

回答

0

只需將%@到位的要添加... searchString這是所有關於您的最終因爲我不知道你要添加的地方

NSString *searchString=searchtextField.text;  

NSString *urlAddress = [NSString stringWithFormat:@"http://api.kivaws.org/v1/loans/search.json?status=%@",searchString]; 

嘗試一下....

+0

例如這是google api .. https://www.googleapis.com/customsearch/v1?key = AIzaSyDzl0Ozijg2C47iYfKgBWWkAbZE_wCJ-2U&cx = 017576662512468239146:omuauf_lfve&q =講座,所以我沒有得到確切在那裏我可以放置 – Abhilash

+0

如果我把searchstring也得到相同的輸出... – Abhilash

+0

這是從你結束你想把searchString –