I wanna generate json file with two-dimensional array as a property like below.
{
“two_dim_array” : [ [0.0, 0.1], [1.0, 1.1] ]
}
How can i generate this json on UE ?
The example of one-dimensional array.
bool UGenerateTwoDimArrayiJson::GenerateTwoDimArrayJsonToFile(FString FilePath) {
TSharedPtr<FJsonObject> JsonRootObject = MakeShareable(new FJsonObject);
TArray<TSharedPtr<FJsonValue>> one_dim_array;
one_dim_array.Add(MakeShareable(new FJsonValueNumber(0.0)));
one_dim_array.Add(MakeShareable(new FJsonValueNumber(0.1)));
one_dim_array.Add(MakeShareable(new FJsonValueNumber(1.0)));
one_dim_array.Add(MakeShareable(new FJsonValueNumber(1.1)));
JsonRootObject->SetArrayField("one_dim_array", one_dim_array);
FString OutPutString;
TSharedRef<TJsonWriter<>> Writer = TJsonWriterFactory<>::Create(&OutPutString);
FJsonSerializer::Serialize(JsonRootObject.ToSharedRef(), Writer);
return FFileHelper::SaveStringToFile(OutPutString, *FilePath);