iOS加载并显示bundle的.txt文件的方法
来源:互联网 发布:城市综合治理大数据 编辑:程序博客网 时间:2024/06/08 01:56
- (void)jiazaitxt{
self.myWebview = [[UIWebViewalloc]initWithFrame:CGRectMake(0,0, [UIScreenmainScreen].bounds.size.width, [UIScreenmainScreen].bounds.size.height+60)];
// myWebView.delegate = self;
//NSString *path = [NSString stringWithFormat:@"%@/Documents/附件/%@",NSHomeDirectory(),self.wendangnaem];
NSString *txtPath=[[NSBundlemainBundle]pathForResource:@"city_list"ofType:@"txt"];
NSLog(@"txtPath:%@",txtPath);
///编码可以解决 .txt中文显示乱码问题
NSStringEncoding *useEncodeing = nil;
//带编码头的如utf-8等,这里会识别出来
NSString *body = [NSStringstringWithContentsOfFile:txtPath usedEncoding:useEncodeing error:nil];
//识别不到,按GBK编码再解码一次.这里不能先按GB18030解码,否则会出现整个文档无换行bug。
if (!body) {
body = [NSStringstringWithContentsOfFile:txtPath encoding:0x80000632error:nil];
NSLog(@"%@",body);
}
//还是识别不到,按GB18030编码再解码一次.
if (!body) {
body = [NSStringstringWithContentsOfFile:txtPath encoding:0x80000631error:nil];
NSLog(@"%@",body);
}
//展现
if (body) {
NSLog(@"%@",body);
NSData *data=[bodydataUsingEncoding:NSUTF8StringEncoding];
NSLog(@"data:%@",data);
id userData=[NSJSONSerializationJSONObjectWithData:data options:NSJSONReadingMutableContainerserror:nil];
if (userData) {
if ([userData isKindOfClass:[NSDictionaryclass]])
{
/*
{"code":"000000","memo":"成功",
"result":
{"domestic":
[{"cityId":"110100","cityName":"北京市","region":[{"regionId":"110101","regionName":"北京市-东城区"},{"regionId":"110102","regionName":"北京市-西城区"},{"regionId":"110103","regionName":"北京市-崇文区"},{"regionId":"110105","regionName":"北京市-朝阳区"},{"regionId":"110106","regionName":"北京市-丰台区"},
*/
NSArray *domesticArray=[(NSDictionary *)userDataobjectForKey:@"domestic"];
for (NSDictionary *dictin domesticArray)
{
QSSMyMessageNowCityModel *model=[[QSSMyMessageNowCityModelalloc]init];
}
}
}
[self.myWebviewloadHTMLString:body baseURL: nil];
}else {
NSString *urlString = [[NSBundlemainBundle] pathForAuxiliaryExecutable:txtPath];
urlString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *requestUrl = [NSURLURLWithString:urlString];
NSLog(@"%@",urlString);
NSURLRequest *request = [NSURLRequestrequestWithURL:requestUrl];
[self.myWebviewloadRequest:request];
}
[selfaddSubview:self.myWebview];
}
- iOS加载并显示bundle的.txt文件的方法
- iOS 加载Bundle文件
- 卸载.bundle文件的方法
- 解析.txt文件的方法
- 读取TXT文件的方法
- vc 加载bmp位图并显示的方法
- C#下载文件并显示显示进度的方法实现
- matlab 加载txt文件的比较。
- Delphi 加载Txt文件中的内容显示在Memo中文字的前面
- 使用Robot从txt文件中读取不同行的内容并显示
- 使用Robot从txt文件中读取不同行的内容并显示(续)
- 使用Robot从txt文件中读取不同行的内容并显示(续二)
- 在TXT文件中查找指定字符串并显示指定字符串所在行的内容
- winform打开本地的txt文件并显示在窗体中
- 读取TXT文件,和生成TXT文件的方法
- 读取TXT文件,和生成TXT文件的方法
- ios Bundle的使用
- iOS开发:PDF文件的加载及显示(网络、本地)
- 一个简单的asp.net 单点登录实现
- Getting Started with Qt 开始使用Qt
- java中向线程中传数据
- Activity的launchMode
- 我一直想做你的阳光
- iOS加载并显示bundle的.txt文件的方法
- ArcGIS教程:了解测量误差
- C#刷新控件的几种方法
- Java-Web定时任务简介
- idea14远程调试tomcat项目
- Intellij IDEA 14中使用MyBatis-generator 自动生成MyBatis代码
- UVa #11093 Just Finish it up (例题8-13)
- Myeclipse中文乱码解决方法
- Android平台JNI程序编译之openssl