JsonString not serializing to UStruct in UE 4.26.2

I’m writing a class to save and read a structure from a file. I’m using the “JsonUtilities” module. Version of my UE: 4.26.2. Saving the structure to a file works correctly, but when I try to use the deserialization method, the compiler throws a bunch of strange errors. For example, here’s the struct I’m using and trying to load data into:

USTRUCT(BlueprintType)
struct FStorageUserData
{
	GENERATED_BODY()

	UPROPERTY(BlueprintReadWrite)
	int32 Id;
	
	UPROPERTY(BlueprintReadWrite)
	FString Name;

	UPROPERTY(BlueprintReadWrite)
	FString Password;
};

The method for loading data from file:

bool UFileManager::GetUser(FStorageUserData& UserData)
{
	const FString Path = FPaths::ProjectDir() + "Users.json";
	FString JsonString;

	if (!FFileHelper::LoadFileToString(JsonString, *Path))
	{
		Log(XXI_Service::Error, "Failed to load the file:" + Path);
		return false;
	}

	FJsonObjectConverter::JsonObjectStringToUStruct(JsonString, &UserData, 0, 0);
	return true;
}

The compiler does not throw any errors. I checked every line of the method and found out that the compiler crashes on the call JsonObjectStringToUStruct (penultimate line).

I tried to copy the code directly from it, and my further attempts showed that the problem is in the method FJsonSerializer::Deserialize, to be even more specific - MakeShared and other places.

I’ve attached a screenshot with the errors I’m getting but can’t figure out due to unreadable compiler coding. I just want to know if this problem is just me or is it a bug in the engine module of a particular version?

1 Like

Try adding “JsonUtilities” to your PublicDependencyModuleNames in your Build.cs file.

Those look like linker errors, not compiler errors.
Although it’s hard to tell, because I can’t read the language the error messages are written in.
If you read the error messages, what do they say?

Of course, these dependencies are written there, otherwise I couldn’t add libraries via #include

I can’t understand these messages either. It’s not some unknown language, it’s just CP866 encoding. I tried to decipher it, but, unfortunately, I didn’t get a clear result. Similar messages I see when trying to use MakeShareable().

Update: installed the language pack, now it became clear that the errors are really somewhere in the dependencies:

All right, after your hint, I realized that there are not enough dependencies. By heuristic selection, I managed to find out that before the “JsonUtilities” I also need to add “Json” in Build.cs :zap:

I guessed it by accident. But, is it possible to find out the exact name of the module without assumptions?

1 Like

Yes you can browse to the symbol that throws an error and look in which module the file is located :

image

2 Likes