Skip to content

how to get value from a json array of parameters? #4290

Answered by gregmarr
StefXinet asked this question in Q&A
Discussion options

You must be logged in to vote

basically using both jitem["name"] or jitem.find("name") i cant find the right element value. Could you help me?

You found the right element, you now just need to extract the data as the right type.

TRACE("name: %s; value: %d\n", jitem["name"], jitem["paramA"]);			// does not work

This doesn't work because you are passing an object of type json with format strings of %s and %d which won't work. The following will work:

TRACE("name: %s; value: %d\n", jitem["name"].get<std::string>().c_str(), jitem["paramA"].get<int>());

or better

std::cout << "name: " << jitem["name"].get<std::string>() << " value: " << jitem["paramA"].get<int>() << "\n";

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by StefXinet
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants