JsonKit使用方法
发布时间:2020-12-16 19:00:01 所属栏目:百科 来源:网络整理
导读:JsonKit使用方法 ,如果在导入JsonKit过程中,编辑出现错误,请参考上一篇文章。 #import "ViewController.h"#import "JSONKit.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; //将Dictionar
JsonKit使用方法 ,如果在导入JsonKit过程中,编辑出现错误,请参考上一篇文章。 #import "ViewController.h" #import "JSONKit.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; //将Dictionary转成Json NSMutableDictionary *jsonDic = [NSMutableDictionary dictionary]; NSMutableDictionary *alert = [NSMutableDictionary dictionary]; NSMutableDictionary *aps = [NSMutableDictionary dictionary]; [alert setObject:@"a msg come!" forKey:@"body"]; [aps setObject:alert forKey:@"alert"]; [aps setObject:@"3" forKey:@"bage" ]; [aps setObject:@"def.mp3" forKey:@"sound"]; [jsonDic setObject:aps forKey:@"aps"]; NSString *strJson = [jsonDic JSONString]; NSLog(@"temp is :%@",strJson); //将json转成Dictionary NSData *data = [strJson dataUsingEncoding:NSUTF8StringEncoding]; NSDictionary *newDic = [data objectFromJSONData]; NSLog(@"newDic= %@",newDic); } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |