2

I have a sample.json with values and an array of values. I'm currently using Json library to parse the json file and read the contents into C++ code. I know how to read a value but not sure about reading an array

Below is the content of sample.json file.

"steering_facts" :
{
    "SteerPolynomial": [0.0, 0.0, -0.0006148, 0.025, 16.24, -0.3823],
    "SteerRatio"     : 0.0
}

Here i can read "SteerRatio" with the help of below code.

static Json::Value  jsonValues;
if (jsonValues.isMember("steering_facts")){
    float steerRatio = jsonValues["steering_facts"]["SteerRatio"].asFloat();
}

But not sure how to read SteerPolynomial array.

1 Answer 1

5

You can write through the following way.

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();
    }
}
Sign up to request clarification or add additional context in comments.

1 Comment

you got it right, i implemented a similar solution and worked for me. Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.