-
Hello, {
"json_info":{
"file_ver":1,
"target":"device1"
},
"map":[
{
"paramA":0,
"paramB":49,
"name":"setting1"
},
{
"paramA":56,
"paramB":-25,
"name":"setting2"
},
{
"paramA":7,
"paramB":34,
"name":"setting3"
}
]
} And I'm reading it like this: int main (){
std::string file_name;
/* some code here to get the right filename and putting it into "file_name" var */
std::ifstream file( file_name );
json jfile = json::parse( file ); // json object with the full JSON file content
json jmap = jfile["map"]; // json object with the map ARRAY
} I can correctly read datas from "json_info" object like this: string target = jfile["json_info"]["target"]; but I really cant understand how to read all the setting* from the "map" array. json jmap = jfile["map"]; // json object with the map ARRAY
int arraysize = jmap.size(); // JSON map array elements, this works well
for( auto it = jmap.begin(); it != jmap.end(); ++it ) { // loops on every array element
json jitem = it.value();
TRACE("name: %s; value: %d\n", jitem["name"], jitem["paramA"]); // does not work
TRACE("name: %s; value: %d\n", jitem.find("name"), jitem.find("paramA")); // does not work
} basically using both jitem["name"] or jitem.find("name") i cant find the right element value. Could you help me? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
You found the right element, you now just need to extract the data as the right type.
This doesn't work because you are passing an object of type
or better
|
Beta Was this translation helpful? Give feedback.
-
You are right, thanks! |
Beta Was this translation helpful? Give feedback.
You found the right element, you now just need to extract the data as the right type.
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:or better