nlohmann-json

Erroring about using push_back function in visual studio 2019 for Azure Kinect

北城以北 提交于 2020-01-06 05:22:09
问题 For line body_result_json["joint_orientations"].push_back({ skeleton.joints[j].orientation.wxyz.w, skeleton.joints[j].orientation.wxyz.x, skeleton.joints[j].orientation.wxyz.y, skeleton.joints[j].orientation.wxyz.z }); I got the error as below: nlohmann::basic_json<std::map, std::vector, std::string, bool, int64_t, uint64_t, double, std::allocator, nlohmann::adl_serializer>" has no member "push_back" offline_processor 来源: https://stackoverflow.com/questions/58595826/erroring-about-using-push

c++ nlohmann json - how to iterate / find a nested object

﹥>﹥吖頭↗ 提交于 2019-12-12 11:46:20
问题 I am trying to iterate over a nested json, using nlohmann::json. My json object is below: { "one": 1, "two": 2 "three": { "three.one": 3.1 }, } I am trying to iterate and /or find nested objects. But, it seems there is no default support for it. It looks like I have to iterate over each sub-object by creating another loop, or call the fn recursively for every sub-object. My following piece of code, and its result indicate, that only top level iteration possible. void findNPrintKey (json src,

nlohmann json ambiguous overload for 'operator='

情到浓时终转凉″ 提交于 2019-12-11 05:48:54
问题 I'm getting this compilation error with the following code #include <iostream> #include <boost/optional.hpp> #include "nlohmann_json.hpp" namespace nlohmann { template <typename T> struct adl_serializer<boost::optional<T>> { static void to_json(json& j, const boost::optional<T>& opt) { if (opt == boost::none) j = nullptr; else j = *opt; } static void from_json(const json& j, boost::optional<T>& opt) { if (j.is_null()) opt = boost::none; else opt = j.get<T>(); } }; } int main(int argc, char*

How to convert a json object to a map with nlohmann::json?

筅森魡賤 提交于 2019-12-11 02:12:16
问题 For example, with nlohmann::json, I can do map<string, vector<int>> m = { {"a", {1, 2}}, {"b", {2, 3}} }; json j = m; But I cannot do m = j; Any way to convert a json object to a map with nlohmann::json? 回答1: The only solution that I found is just to parse it manually. std::map<std::string, std::vector<int>> m = { {"a", {1, 2}}, {"b", {2, 3}} }; json j = m; std::cout << j << std::endl; auto v8 = j.get<std::map<std::string, json>>(); std::map<std::string, std::vector<int>> m_new; for (auto &i

C++: Reading a json object from file with nlohmann json

混江龙づ霸主 提交于 2019-12-03 05:32:49
I am using the nlohmann's json library to work with json objects in c++. Ultimately, I'd like to read a json object from a file, e.g. a simple object like this. { "happy": true, "pi": 3.141 } I'm not quite sure how to approach this. At https://github.com/nlohmann several ways are given to deserialise from a string literal, however it doesn't seem trivial to extend this to read in a file. Does anyone have experience with this? Update 2017-07-03 for JSON for Modern C++ version 3 Since version 3.0 , json::json(std::ifstream&) is deprecated. One should use json::parse() instead: std::ifstream ifs(