本文整理汇总了C++中json::at方法的典型用法代码示例。如果您正苦于以下问题:C++ json::at方法的具体用法?C++ json::at怎么用?C++ json::at使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类json
的用法示例。
在下文中一共展示了json::at方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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 = {};
}
}
示例2: unphysical
void Faunus::Energy::from_json(const json &j, EwaldData &d) {
d.alpha = j.at("alpha");
d.rc = j.at("cutoff");
d.kc = j.at("kcutoff");
d.ipbc = j.value("ipbc", false);
d.spherical_sum = j.value("spherical_sum", true);
d.lB = pc::lB( j.at("epsr") );
d.eps_surf = j.value("epss", 0.0);
d.const_inf = (d.eps_surf < 1) ? 0 : 1; // if unphysical (<1) use epsr infinity for surrounding medium
}
示例3: 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;
}
示例4: PPM
void PPM (const json &j)
{
PMParams params;
params.LoadFrom(j.at("pm_params"));
omp_set_num_threads(params.n_threads);
Scene scene = Scene::Load(j);
Image image(scene.Width() * 2, scene.Height(), "tmp/ph_last", params.display);
PM pm(scene, image, params);
if (j.at("pm_params").at("algo").get<string>() == "ppm")
pm.PPM();
else
pm.PPPM();
image.Show();
image.Dump(-1);
image.Show();
}
示例5: 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;
}
示例6:
Srs::Srs(const json& j)
{
if (j.is_null()) return;
if (j.is_string())
{
*this = Srs(j.get<std::string>());
return;
}
m_authority = j.value("authority", "");
m_horizontal = j.value("horizontal", "");
m_vertical = j.value("vertical", "");
if (j.count("wkt"))
{
m_wkt = j.at("wkt").get<std::string>();
m_spatialReference.set(m_wkt);
}
}
示例7: PT
void PT (const json &j)
{
PTParams params;
params.LoadFrom(j.at("pt_params"));
omp_set_num_threads(params.n_threads);
Scene scene = Scene::Load(j);
Image image(scene.Width() * 2, scene.Height(), "tmp/im_last", params.display);
PathTracer pathTracer(scene, image, params);
Ray ray;
rand_data rd;
rand_init(&rd);
scene.GetCamera()->Project(&rd, 818, 1800 - 1043, ray);
pathTracer.Trace(&rd, ray);
pathTracer.PT();
image.Show();
image.Dump(-1);
image.Show();
}
示例8: main
int main()
{
// create JSON object
json object =
{
{"the good", "il buono"},
{"the bad", "il cattivo"},
{"the ugly", "il brutto"}
};
// output element with key "the ugly"
std::cout << object.at("the ugly") << '\n';
// exception type_error.304
try
{
// use at() on a non-object type
const json str = "I am a string";
std::cout << str.at("the good") << '\n';
}
catch (json::type_error& e)
{
std::cout << e.what() << '\n';
}
// exception out_of_range.401
try
{
// try to read from a nonexisting key
std::cout << object.at("the fast") << '\n';
}
catch (json::out_of_range)
{
std::cout << "out of range" << '\n';
}
}
示例9: processSignalJSON
void IPCClientPrivate::processSignalJSON(const json& jobj)
{
try {
const std::string name = jobj["_s"];
if (name == "DeviceInserted") {
const json attributes_json = jobj.at("attributes");
std::map<std::string,std::string> attributes;
for (auto it = attributes_json.begin(); it != attributes_json.end(); ++it) {
const std::string key = it.key();
const std::string value = it.value();
attributes[key] = value;
}
std::vector<USBInterfaceType> interfaces;
for (auto const& jitem : jobj["interfaces"]) {
const std::string type_string = jitem;
interfaces.push_back(USBInterfaceType(type_string));
}
_p_instance.DeviceInserted(jobj["seqn"],
attributes,
interfaces,
jobj["rule_match"],
jobj["rule_seqn"]);
}
else if (name == "DevicePresent") {
const json attributes_json = jobj.at("attributes");
std::map<std::string,std::string> attributes;
for (auto it = attributes_json.begin(); it != attributes_json.end(); ++it) {
const std::string key = it.key();
const std::string value = it.value();
attributes[key] = value;
}
std::vector<USBInterfaceType> interfaces;
for (auto const& jitem : jobj["interfaces"]) {
const std::string type_string = jitem;
interfaces.push_back(USBInterfaceType(type_string));
}
_p_instance.DevicePresent(jobj["seqn"],
attributes,
interfaces,
Rule::targetFromString(jobj["target"]));
}
else if (name == "DeviceRemoved") {
const json attributes_json = jobj.at("attributes");
std::map<std::string,std::string> attributes;
for (auto it = attributes_json.begin(); it != attributes_json.end(); ++it) {
const std::string key = it.key();
const std::string value = it.value();
attributes[key] = value;
}
_p_instance.DeviceRemoved(jobj["seqn"],
attributes);
}
else if (name == "DeviceAllowed") {
const json attributes_json = jobj.at("attributes");
std::map<std::string,std::string> attributes;
for (auto it = attributes_json.begin(); it != attributes_json.end(); ++it) {
const std::string key = it.key();
const std::string value = it.value();
attributes[key] = value;
}
_p_instance.DeviceAllowed(jobj["seqn"],
attributes,
jobj["rule_match"],
jobj["rule_seqn"]);
}
else if (name == "DeviceBlocked") {
const json attributes_json = jobj.at("attributes");
std::map<std::string,std::string> attributes;
for (auto it = attributes_json.begin(); it != attributes_json.end(); ++it) {
const std::string key = it.key();
const std::string value = it.value();
attributes[key] = value;
}
_p_instance.DeviceBlocked(jobj["seqn"],
attributes,
jobj["rule_match"],
jobj["rule_seqn"]);
}
else if (name == "DeviceRejected") {
const json attributes_json = jobj.at("attributes");
std::map<std::string,std::string> attributes;
for (auto it = attributes_json.begin(); it != attributes_json.end(); ++it) {
const std::string key = it.key();
const std::string value = it.value();
attributes[key] = value;
}
//.........这里部分代码省略.........
示例10: _from_json
void ChainRotationMovebase::_from_json(const json &j) {
molname = j.at("molecule");
dprot = j.at("dprot");
allow_small_box = j.value("skiplarge", true); // todo rename the json attribute and make false default
}
示例11: main
int main()
{
// create a JSON value
const json j =
{
{"number", 1}, {"string", "foo"}, {"array", {1, 2}}
};
// read-only access
// output element with JSON pointer "/number"
std::cout << j.at("/number"_json_pointer) << '\n';
// output element with JSON pointer "/string"
std::cout << j.at("/string"_json_pointer) << '\n';
// output element with JSON pointer "/array"
std::cout << j.at("/array"_json_pointer) << '\n';
// output element with JSON pointer "/array/1"
std::cout << j.at("/array/1"_json_pointer) << '\n';
// out_of_range.109
try
{
// try to use an array index that is not a number
json::const_reference ref = j.at("/array/one"_json_pointer);
}
catch (json::parse_error& e)
{
std::cout << e.what() << '\n';
}
// out_of_range.401
try
{
// try to use a an invalid array index
json::const_reference ref = j.at("/array/4"_json_pointer);
}
catch (json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
// out_of_range.402
try
{
// try to use the array index '-'
json::const_reference ref = j.at("/array/-"_json_pointer);
}
catch (json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
// out_of_range.404
try
{
// try to use a JSON pointer that cannot be resolved
json::const_reference ref = j.at("/number/foo"_json_pointer);
}
catch (json::out_of_range& e)
{
std::cout << e.what() << '\n';
}
}
示例12: SECTION
#include "json.hpp"
using nlohmann::json;
TEST_CASE("element access 1")
{
SECTION("array")
{
json j = {1, 1u, true, nullptr, "string", 42.23, json::object(), {1, 2, 3}};
const json j_const = j;
SECTION("access specified element with bounds checking")
{
SECTION("access within bounds")
{
CHECK(j.at(0) == json(1));
CHECK(j.at(1) == json(1u));
CHECK(j.at(2) == json(true));
CHECK(j.at(3) == json(nullptr));
CHECK(j.at(4) == json("string"));
CHECK(j.at(5) == json(42.23));
CHECK(j.at(6) == json(json::object()));
CHECK(j.at(7) == json({1, 2, 3}));
CHECK(j_const.at(0) == json(1));
CHECK(j_const.at(1) == json(1u));
CHECK(j_const.at(2) == json(true));
CHECK(j_const.at(3) == json(nullptr));
CHECK(j_const.at(4) == json("string"));
CHECK(j_const.at(5) == json(42.23));
CHECK(j_const.at(6) == json(json::object()));
示例13: from_json
void from_json(const json& j, Post& p) {
p.userId = j.at("userId").get<int>();
p.id = j.at("id").get<int>();
p.title = j.at("title").get<string>();
p.body = boost::algorithm::replace_all_copy(j.at("body").get<string>(), "\n", "\\n");
}
示例14: SECTION
*/
#include "catch.hpp"
#include <nlohmann/json.hpp>
using nlohmann::json;
TEST_CASE("version information")
{
SECTION("meta()")
{
json j = json::meta();
CHECK(j["name"] == "JSON for Modern C++");
CHECK(j["copyright"] == "(C) 2013-2017 Niels Lohmann");
CHECK(j["url"] == "https://github.com/nlohmann/json");
CHECK(j["version"] == json(
{
{"string", "3.2.0"},
{"major", 3},
{"minor", 2},
{"patch", 0}
}));
CHECK(j.find("platform") != j.end());
CHECK(j.at("compiler").find("family") != j.at("compiler").end());
CHECK(j.at("compiler").find("version") != j.at("compiler").end());
CHECK(j.at("compiler").find("c++") != j.at("compiler").end());
}
}
示例15: ReadQuery
ReadQuery(const Reader& reader, const json& j)
: Query(reader, j)
, m_schema(j.count("schema") ?
Schema(j.at("schema")) : m_metadata.outSchema())
{ }