1.加载json文件
和加载plist文件类似,给定文件路径即可,不同的是json文件需要加载为data,然后通过json序列化类转换
NSString *path = [[NSBundle mainBundle] pathForResource:@"help.json" ofType:nil];
NSData *data = [NSData dataWithContentsOfFile:path];
NSArray *dictArray = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:NULL];
2.webview加载网页
UIWebView *webView = (UIWebView *)self.view;
webview.frame = self.view.bounds;
webView.delegate = self;
NSString *path = [[NSBundle mainBundle] pathForResource:self.helpModel.html ofType:nil];
NSURL *url = [[NSURL alloc] initFileURLWithPath:path];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
[webView loadRequest:request];
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
NSString *jsStr = [NSString stringWithFormat:@"window.location.href = '#%@';", self.helpModel.tagId];
[webView stringByEvaluatingJavaScriptFromString:jsStr];
}