IOS JSON解析之JSONKit使用

来源:互联网 发布:超硬材料 知乎 编辑:程序博客网 时间:2024/05/18 12:03

JSONKit使用相当简单。
将JSONKit.h和JSONKit.m拖到项目中。
下载地址:https://github.com/johnezang/JSONKit/

下面代码:

//string to dictionary  NSString *resultStr = @"{\"name\": \"admin\",\"list\": [\"one\",\"two\",\"three\"]}";  NSData* jsonData = [resultStr dataUsingEncoding:NSUTF8StringEncoding];  NSDictionary *resultDict = [jsonData objectFromJSONData];  NSLog(@"name is :%@",[resultDict objectForKey:@"name"]);  NSArray *list = [resultDict objectForKey:@"list"];  for (NSString *str in list) {      NSLog(@"list res:%@",str);  }  //dicttionary to string  NSString *jsonStr = [resultDict JSONString];  NSLog(@"temp is :%@",jsonStr);  

转载自:http://blog.csdn.net/qjlhlh/article/details/8126385

0 0
原创粉丝点击