【问题标题】:how to fetch particular method from a json responseString in webview如何从 webview 中的 json responseString 获取特定方法
【发布时间】:2011-06-22 05:45:58
【问题描述】:

我在下面有一个文本字段和按钮以及一个 web 视图。

当我在文本字段中输入字符串并按下搜索按钮时,整个 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];
}

【问题讨论】:

  • 你在哪里添加 searchString in urlAddress 在这段代码中 NSString *urlAddress = [NSString stringWithFormat:@"api.kivaws.org/v1/loans/…;
  • urlAddress stringWithFormat 中没有任何 %@ 格式,您可以添加 searchString
  • 你的 url 是 api 并且输出格式是 JSon..so wat change i shd make in the code?
  • 我说在这段代码中 searchString 的用途是什么,因为你没有在这段代码中的任何地方使用 searchString
  • ex NSString *urlAddress = [NSString stringWithFormat:@"api.kivaws.org/v1/loans/…

标签: iphone objective-c ios xcode json


【解决方案1】:

只需将 %@ 替换为 searchString 您要添加的位置...这就是您要添加的全部内容,因为我不知道您要添加的位置

示例

NSString *searchString=searchtextField.text;    

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

试试看....

【讨论】:

  • 例如,这是 google api..googleapis.com/customsearch/… 所以我没有准确地找到我可以放置的地方
  • 这是你想要放置searchString的地方
  • stringWithFormat:@"google.com/search?q=%@ 这适用于 google.. 但如果我放置 json responsestring 的特定 url 它不会..
  • 你想做的事情请在得到 searchString 后明确告诉我,并明确你想在哪里添加 searchString
  • 从这个api.kivaws.org/v1/loans/search.json你会得到search.json文件
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-09-19
  • 1970-01-01
  • 1970-01-01
  • 2021-08-11
  • 2019-03-30
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多