Well I have been trying to read my UStruct array JSon data but it always sets the UStruct empty. Here’s my JSon data:
[
{
"Sexy little thing":
{
"variable1": "Value1",
"variable2": "Value2",
"variable3": "Value3",
"variable4": "Value4"
}
},
{
"My item":
{
"variable1": "Value1",
"variable2": "Value2",
"variable3": "Value3",
"variable4": "Value4"
}
}
]
And here’s my last code try:
FString dataOnFile;
FFileHelper::LoadFileToString(dataOnFile, TEXT("MyBoringPath/Test JSon"));
//Prints the data correctly
GLog->Log(dataOnFile);
//Not working......
/*TArray<FMyItem> data;
FJsonObjectConverter::JsonArrayStringToUStruct(dataOnFile, &data, 0, 0);*/
TArray<TSharedPtr<FJsonValue>> arrayDeserialized;
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(dataOnFile);
if (FJsonSerializer::Deserialize(Reader, arrayDeserialized))
{
TArray<FMyItem> data;
FJsonObjectConverter::JsonArrayToUStruct(arrayDeserialized, &data, 0, 0);
GLog->Log("Name: " + data[0].variable1);
}
Now the GLog for the data outputs correctly, and even the arrayDeserialized or the data are returning correct size values (They both return 2). But when I try to read the variable1 it’s empty… Here’s my UStruct:
USTRUCT(BlueprintType)
struct FCraftableItem
{
GENERATED_BODY()
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "UProp")
FString variable1;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "UProp")
FString variable2;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "UProp")
FString variable3;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "UProp")
FString variable4;
FCraftableItem()
{
}
FCraftableItem(FString craftedAt, FString variable1, FString variable3, FString variable4)
{
this->variable1= variable1;
this->variable2= variable2;
this->variable3= variable3;
this->variable4= variable4;
}
};
I tried saving my JsonArray inside a FJsonObject and serializing it, but I get the same results. Am I missing something?