zoukankan      html  css  js  c++  java
  • 数组字典转为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

         }

         ]

         }

     

         

         */

     

        

  • 相关阅读:
    随机数表示方法
    何时用重定向何时用转发
    http中重定向和请求转发
    Java正则表达式
    自定义圆形的ProgressBar
    Android内存管理机制
    Android 安全机制
    8位颜色值的含义
    Shape使用
    Bitmap(三)
  • 原文地址:https://www.cnblogs.com/tom2015010203/p/5341063.html
Copyright © 2011-2022 走看看