[英]How can I read an array of object from a JSON file using boost-property-tree in C++
[英]How to read an array of values from json file to c++ array
我有一个带有值和值数组的sample.json。 我目前正在使用Json库来解析json文件并将内容读入C ++代码。 我知道如何读取值,但不确定读取数组
以下是sample.json文件的内容。
"steering_facts" :
{
"SteerPolynomial": [0.0, 0.0, -0.0006148, 0.025, 16.24, -0.3823],
"SteerRatio" : 0.0
}
在这里,我可以借助以下代码阅读“ SteerRatio”。
static Json::Value jsonValues;
if (jsonValues.isMember("steering_facts")){
float steerRatio = jsonValues["steering_facts"]["SteerRatio"].asFloat();
}
但不确定如何读取SteerPolynomial数组。
您可以通过以下方式编写。
static Json::Value jsonValues;
if (jsonValues.isMember("steering_facts")){
float steerRatio = jsonValues["steering_facts"]["SteerRatio"].asFloat();
const Json::Value mynames = jsonValues["steering_facts"]["SteerPolynomial"];
for ( int index = 0; index < mynames.size(); ++index )
{
float poli = mynames[index].asFloat();
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.