I am using FJsonObjectConverter for json deserialization. The result for the first deserialization is correct, but I get an incorrect result for subsequent operations. Maybe I have encountered a situation that belongs to the nature of C++ that I am not familiar with. I am sharing the code and debug results. How do you think I can fix the problem? Thanks.
Debug Result :
As you can see in the json data the “character” property is null but the debugger shows it as previous deserialized data.
Code :
UFUNCTION(BlueprintCallable, Category = "InJson", CustomThunk,
meta = (CustomStructureParam = "StructToFill", DisplayName = "JsonStringToStruct"))
static bool JsonStringToStruct(const FString& JsonString, UStruct*& StructToFill);
DECLARE_FUNCTION(execJsonStringToStruct)
{
P_GET_PROPERTY_REF(FStrProperty, JsonString);
Stack.Step(Stack.Object, nullptr);
const FStructProperty* StructProperty = CastField<FStructProperty>(Stack.MostRecentProperty);
void* StructPtr = Stack.MostRecentPropertyAddress;
P_FINISH;
UStruct* StructDefinition = StructProperty->Struct;
bool bSuccess;
P_NATIVE_BEGIN
bSuccess = Inner_JsonStringToStruct(JsonString, StructDefinition, StructPtr);
P_NATIVE_END
*static_cast<bool*>(RESULT_PARAM) = bSuccess;
}
static bool Inner_JsonStringToStruct(const FString& JsonString, UStruct* StructDefinition, void* StructPtr)
{
TSharedPtr<FJsonObject> JsonObject;
const TSharedRef<TJsonReader<>> JsonReader = TJsonReaderFactory<>::Create(JsonString);
if (!FJsonSerializer::Deserialize(JsonReader, JsonObject) || !JsonObject.IsValid())
{
return false;
}
if (!FJsonObjectConverter::JsonObjectToUStruct(JsonObject.ToSharedRef(), StructDefinition, StructPtr, 0, 0))
{
return false;
}
return true;
}