JsonKit使用方法

前端之家收集整理的这篇文章主要介绍了JsonKit使用方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
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);
}
原文链接:https://www.f2er.com/json/289464.html

猜你在找的Json相关文章