How to access and pass as a function parameter nested json objects in for loop? #2631
-
I send a sequence of several messages in a json object like this: {
"msg1" : {
"time_since_epoch_ms" : 1612969709407,
"timestamp" : "Wed Feb 10 10:08:29 2021\n",
"type" : 1305,
"value" : -999.0
}
"msg2" : {
"time_since_epoch_ms" : 1612969709407,
"timestamp" : "Wed Feb 10 10:08:29 2021\n",
"type" : 1305,
"value" : -999.0
}
} And I'd like to iterate over these messages and pass the nested json to a function. I keep running into this error during linking undefined reference to `(nlohmann::basic_json<std::map, std::vector, std::__cxx11::basic_string<char, std::char_traits, std::allocator >, bool, long, unsigned long, double, std::allocator, nlohmann::adl_serializer, std::vector<unsigned char, std::allocator > >) I have a function And I've tried using range based loops like this I also tried range based loops like below, which works fine for access within the loop to the objects, but I cannot pass the iterator object as json to another function. for (auto &msg : json_object) {
switch ((int)msg["type"]) {
...
func(msg); What is the right way to do this? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
The return value of |
Beta Was this translation helpful? Give feedback.
-
No, I have found a solution ty!
…Sent from my iPhone
On Mar 23, 2021, at 1:24 PM, Niels Lohmann ***@***.***> wrote:
@dreambeyondorange Do you need further assistance?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or unsubscribe.
|
Beta Was this translation helpful? Give feedback.
The return value of
items()
is notnlohmann::json
. You would need to usedeclytype
to derive the type for the definition offunc
.