zoukankan      html  css  js  c++  java
  • ios开发 json数据文件的存取

    将Json存进本地文件夹
     
     
    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");
    -----------------------
     
     
    读取Json
    //==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字典
  • 相关阅读:
    git撤销操作总结
    pull request的一些思考
    设计模式之门面模式
    设计模式之策略模式
    java中的堆栈
    git冲突的处理
    Eclipse 未正常退出,导致进不去的问题
    think in java读后总结---Map集合的几种遍历方式
    maven打包后项目名称不对
    python之正则表达式
  • 原文地址:https://www.cnblogs.com/yjg2014/p/4057991.html
Copyright © 2011-2022 走看看