• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ json类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中json的典型用法代码示例。如果您正苦于以下问题:C++ json类的具体用法?C++ json怎么用?C++ json使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了json类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: from_json

void from_json(const json& j, ToolConfig& a) {
    std::vector<std::string>& files = a.getSourceFiles();
    try {
        files = j.at("source_files").get<std::vector<std::string>>();
    } catch (...) {
        files = {};
    }

    try {
        a.setExecutable(j.at("executable"));
    } catch (...) {
        a.setExecutable("");
    }

    try {
        a.setToolID(j.at("tool_id"));
    } catch (...) {
        a.setToolID("None");
    }

    try {
        a.setVersion(j.at("version"));
    } catch (...) {
        a.setVersion(newVersion);
    }

    std::vector<ToolAction>& actions = a.getActions();
    try {
        actions = j.at("actions").get<std::vector<ToolAction>>();
    } catch (...) {
        actions = {};
    }
}
开发者ID:matzke1,项目名称:rose-develop,代码行数:33,代码来源:ToolConfig.cpp


示例2: read_message

void read_message(int clientID, string message){
    
    // Deserialize message from the string
    json msg = json::parse(message);
    
    if (msg["MESSAGE_TYPE"] == "CLIENT_UPDATE") {
        
        // Send a time stamp reply for client-side latency estimation
        json tStamps;
		tStamps["MESSAGE_TYPE"] = "TIME_STAMP_REPLY";
        tStamps["T2"] = chrono::system_clock::now().time_since_epoch() / chrono::milliseconds(1); // Time received
        tStamps["T1"] = msg["TIME_STAMP"]; // Origination time
        send_message(clientID, tStamps);
        
        // Now, process the client update:
        // Scenario A: We don't have a game ready yet. This is a pre-game message.
        if (game_p == NULL) {
            
            // Step 1: Put the message in the correct bin.
            pregame_player_msgs[clientID] = msg;
            
            // Step 2: If both bins are filled (2 players ready),
            // then start a new game.
            if (pregame_player_msgs.size() == 2) {
                game_p = new SnakeGame(pregame_player_msgs[0], pregame_player_msgs[1]);
                pregame_player_msgs.clear();
            }
        }
        
        // Scenario B: A game already exists. Just forward the message to it.
        else {
            game_p->handleClientInput(msg);
        }
    }
}
开发者ID:jasaaved,项目名称:Resume,代码行数:35,代码来源:main.cpp


示例3: merge

 json merge(const json &a, const json &b) {
     json result = a.flatten();
     json tmp = b.flatten();
     for ( auto it = tmp.begin(); it != tmp.end(); ++it )
         result[it.key()] = it.value();
     return result.unflatten();
 }
开发者ID:gitesei,项目名称:faunus,代码行数:7,代码来源:core.cpp


示例4: from_json

 void from_json(const json &j, AtomData &a) {
     if (j.is_object()==false || j.size()!=1)
         throw std::runtime_error("Invalid JSON data for AtomData");
     for (auto it : j.items()) {
         a.name = it.key();
         auto& val = it.value();
         a.activity = val.value("activity", a.activity) * 1.0_molar;
         a.alphax   = val.value("alphax", a.alphax);
         a.charge   = val.value("q", a.charge);
         a.dp       = val.value("dp", a.dp) * 1.0_angstrom;
         a.dprot    = val.value("dprot", a.dprot) * 1.0_rad;
         a.eps      = val.value("eps", a.eps) * 1.0_kJmol;
         a.id()     = val.value("id", a.id());
         a.mu       = val.value("mu", a.mu);
         a.mulen    = val.value("mulen", a.mulen);
         a.scdir    = val.value("scdir", a.scdir);
         a.sclen    = val.value("sclen", a.sclen);
         a.mw       = val.value("mw", a.mw);
         a.sigma    = val.value("sigma", 0.0) * 1.0_angstrom;
         if (fabs(a.sigma)<1e-20)
             a.sigma = 2.0*val.value("r", 0.0) * 1.0_angstrom;
         a.tension  = val.value("tension", a.tension) * 1.0_kJmol / (1.0_angstrom*1.0_angstrom);
         a.tfe      = val.value("tfe", a.tfe) * 1.0_kJmol / (1.0_angstrom*1.0_angstrom*1.0_molar);
         a.hydrophobic = val.value("hydrophobic", false);
     }
 }
开发者ID:bearnix,项目名称:faunus,代码行数:26,代码来源:atomdata.cpp


示例5: fromJSON

void Colour::fromJSON(json& jvalue)
{
  //Will accept integer colour or [r,g,b,a] array or 
  // string containing x11 name or hex #rrggbb or html rgba(r,g,b,a) 
  if (jvalue.is_number())
  {
    value = jvalue;
  }
  else if (jvalue.is_array())
  {
    float R = jvalue[0];
    float G = jvalue[1];
    float B = jvalue[2];
    float A = 1.0;
    if (jvalue.size() > 3) A = jvalue[3];
    if (R <= 1.0 && G <= 1.0 && B <= 1.0 && A <= 1.0)
    {
      r = R*255.0;
      g = G*255.0;
      b = B*255.0;
      a = A*255.0;
    }
    else
    {
      r = R;
      g = G;
      b = B;
    }
  }
  else if (jvalue.is_string())
  {
    fromString(jvalue);
  }
  //std::cout << "COLOUR: " << std::setw(2) << jvalue << " ==> " << *this << std::endl;
}
开发者ID:OKaluza,项目名称:LavaVu,代码行数:35,代码来源:Colours.cpp


示例6: parseJson

void LogEntryRootFilter::parseJson(const json &j) {
    auto filterType_json = j.find("filterType");
    if (filterType_json != j.end()) {
        filterType = (FilterType) filterType_json->get<int>();
    } else {
        filterType = filterIn;
    }
}
开发者ID:yhd4711499,项目名称:LogUtil,代码行数:8,代码来源:LogEntryRootFilter.cpp


示例7: ensureType

	void JsonUtil::ensureType(const string& aFieldName, const json& aNew, const json& aExisting) {
		if (aExisting.is_number()) {
			if (!aNew.is_number()) {
				throwError(aFieldName, ERROR_INVALID, "The new value must be a number");
			}
		} else if (aNew.type() != aExisting.type()) {
			throwError(aFieldName, ERROR_INVALID, "Type of the new value doesn't match with the existing type");
		}
	}
开发者ID:airdcpp,项目名称:airdcpp-webapi,代码行数:9,代码来源:JsonUtil.cpp


示例8: to_dict

QM_NAMESPACE

boost::python::dict to_dict(json const& self)  {
	boost::python::dict d;
	for(json::const_iterator it=self.begin();it!=self.end();++it)  {
		d[it->first] = it->second;
	}
	return d;
}
开发者ID:algotrust,项目名称:qmlib,代码行数:9,代码来源:json_wrap.cpp


示例9: read_meas_array

std::shared_ptr<dariadb::MeasArray>
read_meas_array(const dariadb::scheme::IScheme_Ptr &scheme, const json &js) {
  auto result = std::make_shared<dariadb::MeasArray>();
  auto js_iter = js.find("append_values");
  if (js_iter == js.end()) {
    dariadb::logger_fatal("append_values not found");
    return nullptr;
  }

  auto values = *js_iter;
  for (auto it = values.begin(); it != values.end(); ++it) {
    dariadb::MeasArray sub_result;
    auto id_str = it.key();
    auto val4id = it.value();

    dariadb::Id id = scheme->addParam(id_str);

    auto flag_js = val4id["F"];
    auto val_js = val4id["V"];
    auto time_js = val4id["T"];

    if (flag_js.size() != val_js.size() || time_js.size() != val_js.size()) {
      THROW_EXCEPTION("bad query format, flags:", flag_js.size(),
                      " values:", val_js.size(), " times:", time_js.size(),
                      " query: ", js.dump(1));
    }

    sub_result.resize(flag_js.size());
    size_t pos = 0;
    for (auto f_it = flag_js.begin(); f_it != flag_js.end(); ++f_it) {
      dariadb::Flag f = *f_it;
      sub_result[pos++].flag = f;
    }

    pos = 0;
    for (auto v_it = val_js.begin(); v_it != val_js.end(); ++v_it) {
      dariadb::Value v = *v_it;
      sub_result[pos++].value = v;
    }

    pos = 0;
    for (auto t_it = time_js.begin(); t_it != time_js.end(); ++t_it) {
      dariadb::Time t = *t_it;
      sub_result[pos++].time = t;
    }

    dariadb::logger("in query ", sub_result.size(), " values for id:", id);
    for (auto v : sub_result) {
      v.id = id;
      result->push_back(v);
    }
  }
  return result;
}
开发者ID:lysevi,项目名称:dariadb,代码行数:54,代码来源:query_parser.cpp


示例10:

RenderableSpriteBlueprint::RenderableSpriteBlueprint(json& j) {
    if (j.count("diffuse")) {
        _diffuse = j["diffuse"].get<std::string>();
    }
    if (j.count("normal")) {
        _normal = j["normal"].get<std::string>();
    }
    if (j.count("lit")) {
        _lit = j["lit"].get<bool>();
    }
}
开发者ID:citiral,项目名称:Yeast,代码行数:11,代码来源:RenderableSpriteBlueprint.cpp


示例11: filterExactValues

	json JsonUtil::filterExactValues(const json& aNew, const json& aCompareTo) noexcept {
		json ret = aNew;
		for (const auto& v: json::iterator_wrapper(aCompareTo)) {
			auto key = v.key();
			auto i = aNew.find(key);
			if (i != aNew.end() && aNew.at(key) == aCompareTo.at(key)) {
				ret.erase(key);
			}
		}

		return ret;
	}
开发者ID:airdcpp,项目名称:airdcpp-webapi,代码行数:12,代码来源:JsonUtil.cpp


示例12:

	optional<int> FavoriteHubUtils::deserializeIntHubSetting(const string& aFieldName, const json& aJson) {
		auto p = aJson.find(aFieldName);
		if (p == aJson.end()) {
			return boost::none;
		}

		if ((*p).is_null()) {
			return HUB_SETTING_DEFAULT_INT;
		}

		return JsonUtil::parseValue<int>(aFieldName, *p);
	}
开发者ID:sbraz,项目名称:airdcpp-webclient,代码行数:12,代码来源:FavoriteHubUtils.cpp


示例13: ValidateArguments

bool RPCMethod::ValidateArguments(json j) {
  if (j.size() != this->paramTypes->size()) {
    return false;
  }

  for (unsigned int c = 0; c < this->paramTypes->size(); c++) {
    if (!this->checkType(this->paramTypes->at(c), j.at(c))) {
      return false;
    }
  }
  return true;
}
开发者ID:Dreae,项目名称:sm-ext-rpc,代码行数:12,代码来源:RPCMethod.cpp


示例14:

RenderableBackgroundBlueprint::RenderableBackgroundBlueprint(json& j) {
    if (j.count("diffuse")) {
        _diffuse = j["diffuse"].get<std::string>();
    }
    if (j.count("normal")) {
        _normal = j["normal"].get<std::string>();
    }
    if (j.count("scale")) {
        _scale = j["scale"].get<float>();
    } else {
        _scale = 1;
    }
}
开发者ID:citiral,项目名称:Yeast,代码行数:13,代码来源:RenderableBackgroundBlueprint.cpp


示例15: Color

LightBlueprint::LightBlueprint(json& j) {
    _type = j["type"];

    if (j.count("x")) _x = j["x"].get<float>();
    if (j.count("y")) _y = j["y"].get<float>();
    if (j.count("z")) _z = j["z"].get<float>();
    if (j.count("drop")) _drop = j["drop"].get<float>();
    if (j.count("end")) _end = j["end"].get<float>();
    if (j.count("depth")) _depth = j["depth"].get<float>();
    if (j.count("color")) {
        _color = Color(j["color"][0], j["color"][1], j["color"][2]);
    }
}
开发者ID:citiral,项目名称:Yeast,代码行数:13,代码来源:LightBlueprint.cpp


示例16: _from_json

 void Movebase::from_json(const json &j) {
     auto it = j.find("repeat");
     if (it!=j.end()) {
         if (it->is_number())
             repeat = it->get<double>();
         else
         if (it->is_string())
             if (it->get<std::string>()=="N")
                 repeat = -1;
     }
     _from_json(j);
     if (repeat<0)
         repeat=0;
 }
开发者ID:gitesei,项目名称:faunus,代码行数:14,代码来源:move.cpp


示例17: checkType

bool RPCMethod::checkType(ParamType type, json j) {
  switch (type) {
  case ParamType::Bool:
    return j.is_boolean();
  case ParamType::Int:
    return j.is_number_integer();
  case ParamType::Float:
    return j.is_number();
  case ParamType::String:
    return j.is_string();
  case ParamType::JSON:
    return true;  
  }
}
开发者ID:Dreae,项目名称:sm-ext-rpc,代码行数:14,代码来源:RPCMethod.cpp


示例18: value_inf

 double value_inf(const json &j, const std::string &key) {
     auto it = j.find(key);
     if (it==j.end())
         throw std::runtime_error("unknown json key '" + key + "'");
     else
         if (it->is_string()) {
             if (*it=="inf")
                 return std::numeric_limits<double>::infinity();
             if (*it=="-inf")
                 return -std::numeric_limits<double>::infinity();
             throw std::runtime_error("value must be number or 'inf'");
         }
     return double(*it);
 }
开发者ID:gitesei,项目名称:faunus,代码行数:14,代码来源:core.cpp


示例19: GenStat

static void GenStat(Stat& stat, const json& v) {
    switch (v.type()) {
    case value_types::array_t:
        for (json::const_array_iterator itr = v.begin_elements(); itr != v.end_elements(); ++itr)
            GenStat(stat, *itr);
        stat.arrayCount++;
        stat.elementCount += v.size();
        break;

    case value_types::empty_object_t:
    case value_types::object_t:
        for (json::const_object_iterator itr = v.begin_members(); itr != v.end_members(); ++itr) {
            GenStat(stat, itr->value());
            stat.stringLength += itr->name().size();
        }
        stat.objectCount++;
        stat.memberCount += v.size();
        stat.stringCount += v.size();
        break;

    case value_types::string_t: 
        stat.stringCount++;
        stat.stringLength += v.as_string().size();
        break;

    case value_types::small_string_t:
        stat.stringCount++;
        stat.stringLength += v.as_string().size();
        break;

    case value_types::double_t:
    case value_types::integer_t:
    case value_types::uinteger_t:
        stat.numberCount++;
        break;

    case value_types::bool_t:
        if (v.as_bool())
            stat.trueCount++;
        else
            stat.falseCount++;
        break;

    case value_types::null_t:
        stat.nullCount++;
        break;
    }
}
开发者ID:miloyip,项目名称:nativejson-benchmark,代码行数:48,代码来源:jsonconstest.cpp


示例20: material_property

linear_diffusion::linear_diffusion(json const& material_data) : material_property(material_data)
{
    if (material_data.find("conductivity") != material_data.end())
    {
        m_conductivity = material_data["conductivity"];
    }
    if (material_data.find("specific_heat") != material_data.end())
    {
        m_specific_heat = material_data["specific_heat"];
    }
    else
    {
        throw std::domain_error("\"specific_heat\" needs to be specified as a material "
                                "property");
    }
}
开发者ID:dbeurle,项目名称:neon,代码行数:16,代码来源:linear_diffusion.cpp



注:本文中的json类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ json_config_iarchive_cast类代码示例发布时间:2022-05-31
下一篇:
C++ ivector类代码示例发布时间:2022-05-31
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap