IOS JSON解析之JSONKit使用
JSONKit使用相当简单。将JSONKit.h和JSONKit.m拖到项目中。下载地址:https://github.com/johnezang/JSONKit/下面代码://string to dictionaryNSString *resultStr = @"{\"name\": \"admin\",\"list\": [\"one\",\"two\",\"
文章共119字 · 阅读需要大约1分钟
一键AI生成摘要,助你高效阅读
问答
·
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);
更多推荐
已为社区贡献1条内容
所有评论(0)