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字典
  • 相关阅读:
    贝叶斯定理
    用matplotlib统计数据并画图
    词云图
    一行python代码能写出啥?
    用python生成二维码
    18个python的高效编程技巧
    django简介
    vue点击变色
    selenium破解人人登陆验证码
    selenium请求豆瓣网
  • 原文地址:https://www.cnblogs.com/cranz-jf/p/5207637.html
Copyright © 2011-2022 走看看