{
msg = "操作成功",
data = (
{
name = "初级课程",
state = "1",
},
{
name = "中级课程",
state = "2",
},
{
name = "高级课程",
state = "2",
},
),
code = "0",
}
{
"msg": "操作成功",
"data": [
{
"name" : "初级课程",
"state" : "1",
},
{
"name" : "中级课程",
"state" : "2",
},
{
"name" : "高级课程",
"state" : "2",
}
],
"code": "0"
}
+(NSDictionary*)readTextToJsonDictionByName:(NSString*)name{
NSString *defaultData = [[NSBundle mainBundle] pathForResource:name ofType:@"txt"];
NSString *string = [[NSString alloc] initWithContentsOfFile:defaultData encoding:NSUTF8StringEncoding error:nil];
NSData * resData = [[NSData alloc]initWithData:[string dataUsingEncoding:NSUTF8StringEncoding]];
NSError* error;
NSDictionary *resultDic = [NSJSONSerialization JSONObjectWithData:resData options:NSJSONReadingMutableContainers error:&error];
if (error) {
DGLog(@"JSON解析失败: %@",error);
}
return resultDic;
}
总是报错:
Error Domain=NSCocoaErrorDomain Code=3840 "Unescaped control character around character 47." UserInfo={NSDebugDescription=Unescaped control character around character 47.}