zoukankan      html  css  js  c++  java
  • iOS中 JSON格式文件的写入和读取

    1、写入(本地)

        NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *path=[paths objectAtIndex:0];
        NSString *Json_path=[path stringByAppendingPathComponent:@"JsonFile.json"];
        //==写入文件
        NSLog(@"%@",[JsonData writeToFile:Json_path atomically:YES] ? @"Succeed":@"Failed");

    2、读取

    //==Json文件路径
        NSArray *paths=NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *path=[paths objectAtIndex:0];
        NSString *Json_path=[path stringByAppendingPathComponent:@"JsonFile.json"];
        //==Json数据
        NSData *data=[NSData dataWithContentsOfFile:Json_path];
        //==JsonObject

        id JsonObject=[NSJSONSerialization JSONObjectWithData:data
                                                       options:NSJSONReadingAllowFragments
                                                         error:&error]
      //nslog (@"%@",jsonobject);打印json字典
  • 相关阅读:
    unix网络编程源码编译问题
    ubuntu15.04下安装docker
    hexo博客的相关配置
    hexo的jacman主题配置
    使用github和hexo搭建静态博客
    操作系统简单认识
    github for windows安装以及教程
    编译原理第五单元习题
    python3入门之列表和元组
    Python3入门之软件安装
  • 原文地址:https://www.cnblogs.com/cranz-jf/p/5207637.html
Copyright © 2011-2022 走看看