iOS开发代码:从文本文件中读取内容到字符串里(+ .json文件)
2014-06-10 10:36
676 查看
iOS开发代码:从文本文件中读取内容到字符串里
NSError *error;NSString *textFileContents = [NSString
stringWithContentsOfFile:[[NSBundle mainBundle]
pathForResource:@”myTextFile”
ofType:@”txt”]
encoding:NSUTF8StringEncoding
error: & error];
// If there are no results, something went wrong
if (textFileContents == nil) {
// an error occurred
NSLog(@”Error reading text file. %@”, [error localizedFailureReason]);
}
NSArray *lines = [textFileContents componentsSeparatedByString:@” ”];
NSLog(@”Number of lines in the file:%d”, [lines count] );
NSError *error;
NSString *textFileContents = [NSString
stringWithContentsOfFile:
[[NSBundle
mainBundle] pathForResource:@"hua"
ofType:@"json"]
encoding:NSUTF8StringEncoding
error: & error];
if (error) {
NSLog(@"error %@", error);
}
id jsonObj = [textFileContents
jsonObject];
NSMutableArray *item = jsonObj;
相关文章推荐
- iOS开发代码:从文本文件中读取内容到字符串里
- 小白学开发(iOS)OC_ 从文件中读取字符串内容(201 4000 5-08-14)
- ios本地文件内容读取,.json .plist 文件读写
- ios本地文件内容读取,.json .plist 文件读写
- AB程序核心代码(MFC从文件读取一行+MFC字符串处理+C在文件末尾追加内容)
- iOS学习笔记21—从文本文件中读取内容到字符串里
- ios本地文件内容读取json .plist 文件读取
- Hpple-iOS解析HTML-hpple读取html文件内容的代码 更新了下拉刷新功能
- PHP 读取和修改大文件的某行内容的代码
- iOS开发之一些字符串常用的代码
- iOS对json文件的读取
- iOS开发之一些字符串常用的代码
- C++代码一次读取文本文件全部内容到string对象
- Java读取文件内容并转换为字符串
- jQuery ajax读取json文件内容
- PHP读取文件所有内容到字符串 file_get_contents
- iOS开发2:读取plist文件
- php读取文件内容至字符串中,同时去除换行、空行、行首行尾空格(Zjmainstay原创)
- 读取Htm文件内容到字符串
- iOS开发之一些字符串常用的代码