Hi,
I tried to figure it out on my own, but it appears my knowledge is subzero on C++ for Unreal…
I would like to read out a file, which contains the following information:
{
"Level": {
"Name": "Level001",
"Description": "This is the introductory level with full support."
}
}
I do this using the following code:
FLevelInfo LevelInfo;
FString JsonString = ReadFile(Path);
TSharedPtr<FJsonObject> JsonObject;
TSharedRef< TJsonReader<> > Reader = TJsonReaderFactory<>::Create(JsonString);
UE_LOG(LogTemp, Warning, TEXT("Load %s"), *Path);
if (FJsonSerializer::Deserialize(Reader, JsonObject))
{
// This nicely shows the dump of the entire file
UE_LOG(LogTemp, Warning, TEXT("Level %s"), *JsonString);
// Up until this point all goes as planned.
// This is supposed to parse the String into the LevelInfo UStruct
FJsonObjectConverter::JsonObjectStringToUStruct(*JsonString, &LevelInfo, 0, 0);
// I would expect the variable des to contain the Description text but it is empty...
FString des = LevelInfo.Description;
UE_LOG(LogTemp, Warning, TEXT("Description %s"), *des);
}
So, instead of reading out the information from the JSonObject into the LevelInfo UStruct, nothing is happening…
This is the UStruct:
USTRUCT(BlueprintType)
struct FLevelInfo
{
GENERATED_BODY()
public:
UPROPERTY(BlueprintReadWrite, Category = "Level")
FString Name;
UPROPERTY(BlueprintReadWrite, Category = "Level")
FString Description;
};
I kept this experiment simple to understand how to do this. However, even this simple UStruct cannot be read using this method…
Any ideas what I am doing wrong?
Thanks!