数组字典转为json

    NSMutableDictionary *dic = [[NSMutableDictionary alloc] init];

    [dic setValue:@"标签内容" forKey:@"content"];

    [dic setValue:@257 forKey:@"x"];

    [dic setValue:@264 forKey:@"y"];

    NSMutableArray *array = [[NSMutableArray alloc] initWithObjects:dic, nil];

    NSMutableDictionary *endDic = [[NSMutableDictionary alloc] init];

    [endDic setValue:array forKey:@"tagInfosList"];

    NSData *data = [NSJSONSerialization dataWithJSONObject:endDic options:NSJSONWritingPrettyPrinted error:nil];

    NSString *jsonString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];

    

    NSLog(@"转化为json %@",jsonString);

 

    /*

     {

     "tagInfosList" : [

     {

     "content" : "标签内容",

     "x" : 257,

     "y" : 264

     }

     ]

     }

 

     

     */

 

    

原文地址:https://www.cnblogs.com/tom2015010203/p/5341063.html