zoukankan      html  css  js  c++  java
  • ios 把数组对象转成json字符串存起来

    1第一步是我们获取数据源

    一般我们都是从接口请求数据

     NSArray *subColumnsArray = nil;

    NSDictionary *dict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers  error:nil];

    //保存到数据源,用数组接收

     if ([dict isKindOfClass:[NSDictionary class]]){

            subColumnsArray = [dict objectForKey:@"subColumns"];

        }

    2第二部就是存一个json字符串到数据源中

    if(subColumnsArray != nil){

          //把数组对象传承json字符串存起来

            NSData *jsonData = [NSJSONSerialization dataWithJSONObject:subColumnsArray options:NSJSONWritingPrettyPrinted error:nil];

            NSString *subColumns = [[NSString alloc]initWithData:jsonData encoding:NSUTF8StringEncoding];

           //初始化个字典copy所有对象那个 

            NSDictionary *copydic = [[mutableArray lastObject] mutableCopy];

           //修改字段赋值  然后保存到数据库用title字段来保存

               [copydic setValue:subColumns forKey:@"title"];

            //插入到第几个位置

        }

    3,接着这是你需要数据源的地方取值,取值需要在给他转化如果存的时候是数组,你转化成熟组,如果存的是字典就转换成字典

        //转换成字典,然后用数组接收  然后cell赋值,把数据源去setmodel

           NSData *jsonData = [article.title dataUsingEncoding:NSUTF8StringEncoding];

            NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData

                                                                options:NSJSONReadingMutableContainers

                                                                  error:nil];

            NSArray *arr = [Column mj_objectArrayWithKeyValuesArray:dic];

            cell.imagesModels = arr;

  • 相关阅读:
    2015年9月29日html基础加强学习笔记
    2015年9月30日html表单笔记
    2015年10月1日登陆界面表单练习
    linux 常用命令
    OSI七层模型与TCP/IP层次模型
    谈谈字符串那点事
    vim 常用命令
    VB Pcode 动态调试要点
    数据类型方法
    join()和fromkeys()的用法与注意事项
  • 原文地址:https://www.cnblogs.com/whx060900/p/10508864.html
Copyright © 2011-2022 走看看