iOS json字符串转化为NSArray(解析)
来源:互联网 发布:淘宝宝贝怎么靠前 编辑:程序博客网 时间:2024/05/21 05:21
URL:http://www.12beli.com/App/Index/Category?pid=0 往服务器发数据返回的是数组
服务器返回数据如下:
dict-123--{
CategoryName = Komputer;
ID = 4;
ParentID = 0;
child = "[{\"ID\":16,\"CategoryName\":\"Laptop\",\"ParentID\":4},{\"ID\":15,\"CategoryName\":\"Desktop\",\"ParentID\":4},{\"ID\":14,\"CategoryName\":\"Printer\",\"ParentID\":4},{\"ID\":24,\"CategoryName\":\"Aksesori Komputer\",\"ParentID\":4},{\"ID\":21,\"CategoryName\":\"Proyektor\",\"ParentID\":4},{\"ID\":204,\"CategoryName\":\"Networking\",\"ParentID\":4},{\"ID\":209,\"CategoryName\":\"Lain-Lain\",\"ParentID\":4},{\"ID\":215,\"CategoryName\":\"Hardware\",\"ParentID\":4}]";
}-
如要取child里面的内容需要将json字符串转换,否则按正常取法的话会crash
参考:
NSMutableString *jsonDataString=[NSMutableString string];
[jsonDataString setString:[NSString stringWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"jsonData" ofType:@"txt"] encoding:NSUTF8StringEncoding error:nil]];
NSData *nsData=[jsonDataString dataUsingEncoding:NSUTF8StringEncoding];
parsedArray=[NSJSONSerialization JSONObjectWithData:nsData options:kNilOptions error:nil];
我解析的内容 (ASIHTTPRequest)
- (void)requestFinished:(ASIHTTPRequest *)request
{
SBJSON * json = [[SBJSONalloc]init];
_dataArray = [jsonobjectWithString:[requestresponseString]error:nil];
if ([_dataArraycount] !=0) {
for (NSDictionary * dictin_dataArray) {
NSString *str= [dictobjectForKey:@"child"];
NSData *nsData=[strdataUsingEncoding:NSUTF8StringEncoding];
NSArray *childArray=[NSJSONSerializationJSONObjectWithData:nsDataoptions:kNilOptionserror:nil];
if ( childArray !=nil ) {
// for(int i=0;i<[childArray count];i++)
// {
// [childArray objectAtIndex:i];
// }
for (NSDictionary * littleDictin childArray) {
NSString * name = [littleDictobjectForKey:@"CategoryName"];
}
}
}
}
}
- iOS json字符串转化为NSArray(解析)
- ios json解析数据转化为中文
- 将JSON转化为NSArray或者NSDictionary
- 转化为json字符串
- json转化为字符串
- iOS对象(字典或数组)转化为JSon字符串
- iOS-OC-把JSON字符串转化为字典
- iOS对象(字典或数组)转化为JSon字符串
- IOS基础-NSArray、NSDictionary转JSON字符串
- json数组转化为字符串
- 字典转化为 json 字符串
- json字符串转化为对象
- JSON字符串转化为字典
- 枚举转化为JSON字符串
- JSON字符串与NSDictionary和NSArray之间的转化
- iOS json转化为model
- 解析json将json转化为DataTable
- 【javascript】Json字符串转化为Json数据
- 存储properties资源文件
- rj45接口定义/rj45针脚定义/rj45引脚定义
- 【IOS学习】之九、Blocks的实现续
- Properties资源文件工具类
- 自定义Annotation
- iOS json字符串转化为NSArray(解析)
- 一个bug
- 【IOS学习】之九、Blocks的实现再续
- HDU解题报告--1004
- A^B
- UVa 10194 足球
- 使用FileUtils简化你的文件操作
- 如何进行嵌入式开发
- springMVC JSON的接受和发送