zoukankan      html  css  js  c++  java
  • vjson.hpp

    //vov
    #ifndef VJSON_HPP
    #define VJSON_HPP
    
    #include <iostream>
    #include <string>
    #include "json.hpp"
    
    using vJson=nlohmann::json;
    
    bool  vJsonFromFile(vJson &json_data,const std::string& fname) {
        std::fstream ifs(fname,std::fstream::in);
        try {
            ifs>>json_data;
        }
        catch(std::exception &e) {
            std::cout<<"["<<__FUNCTION__<<"]"<<e.what()<<"
    ";
            ifs.close();
            return false;
        }
        ifs.close();
        return true;
    }
    
    bool vJsonToFile(vJson &json_data,const std::string& fname) {
        std::fstream ofs(fname,std::fstream::out);
        try {
            ofs<<json_data.dump(4);
        }
        catch(std::exception &e) {
            std::cout<<"["<<__FUNCTION__<<"]"<<e.what()<<"
    ";
            return false;
        }
        ofs.close();
        return true;
    }
    
    bool vJsonHasKey(vJson &json_data,const std::string &key) {
        return (json_data.find(key)!=json_data.end())?true:false;
    }
    
    #endif
    
  • 相关阅读:
    STL——pair
    STL——stack
    Python学习之编程基础
    开学第一课,课课有总结
    DNS域名解析
    FTP文件传输服务
    DHCP原理及配置
    Linux中配置网卡
    indoe与block解析
    Linux系统安全管理
  • 原文地址:https://www.cnblogs.com/smallredness/p/10774989.html
Copyright © 2011-2022 走看看