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字典
  • 相关阅读:
    课后作业10.13
    大道至简:软件工程实践者的思想 读后感
    课程作业01
    动手动脑10.13
    动手动脑
    js矢量图类库:Raphaël—JavaScript Library
    OSGi bundle之间互相通信的方法
    OSGi bundle 与 fragment
    Spring.DM web 开发环境搭建
    Spring.DM版HelloWorld
  • 原文地址:https://www.cnblogs.com/yjg2014/p/4057991.html
Copyright © 2011-2022 走看看