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

         }

         ]

         }

     

         

         */

     

        

  • 相关阅读:
    STM32的低功耗模式
    C语言的面向对象技术
    SDIO学习
    读十倍效率开发者有感
    三极管
    压敏电阻
    freertos之任务
    tsar采集数据原理
    NTP学习路线
    使用awk提取字符串中的数字或字母
  • 原文地址:https://www.cnblogs.com/tom2015010203/p/5341063.html
Copyright © 2011-2022 走看看