0

I want to parse the following array of arrays using rapidjson. My code environment is VS2019 with Unreal Engine v4.24.3. I am new to C++.

const char* json = "{ \"data\":[[0.0,1.1],[2.1,3.1]] }";

I have already referred to Rapidjson , get a value inside an array of another array & Processing arrays of arrays of integer with rapidjson

For the integer array of arrays following code works just fine.

const char* json = "{ \"data\":[[0,1],[2,3]] }";

Document d;
d.Parse(json);

const rapidjson::Value& b = d["data"];

for (rapidjson::SizeType i = 0; i < b.Size(); i++)
{
    const rapidjson::Value& c = b[i];
    UE_LOG(LogTemp, Log, TEXT("%d: Test Data"), c[rapidjson::SizeType(0)].GetInt());
}

Returns->

LogTemp: 0: Test Data //Expected values
LogTemp: 2: Test Data

But for the array of arrays with Float values, the following code does not work.

const char* json = "{ \"data\":[[0.5,1.1],[2.1,3.1]] }";

Document d;
d.Parse(json);

const rapidjson::Value& b = d["data"];

for (rapidjson::SizeType i = 0; i < b.Size(); i++)
{
    const rapidjson::Value& c = b[i];
    UE_LOG(LogTemp, Log, TEXT("%d: test Data"), c[rapidjson::SizeType(0)].GetFloat());
}

returns ->

LogTemp: 0: test Data
LogTemp: -1073741824: test Data

How can I figure this out? What am I missing?

UpaJah
  • 6,954
  • 4
  • 24
  • 30

1 Answers1

0

floating point specifier %f should be used for the float data type.

const char* json = "{ \"data\":[[0.5,1.1],[2.1,3.1]] }";

Document d;
d.Parse(json);

const rapidjson::Value& b = d["data"];

for (rapidjson::SizeType i = 0; i < b.Size(); i++)
{
    const rapidjson::Value& c = b[i];
    UE_LOG(LogTemp, Log, TEXT("%f: test Data"), c[rapidjson::SizeType(0)].GetFloat());
}
UpaJah
  • 6,954
  • 4
  • 24
  • 30