Compiling Errors when using JsonArrayStringToUStruct

Currently I’m trying to convert json string to struct array and I find a function JsonArrayStringToUStruct, however there’s always some compiling error. Below is my .h:

#pragma once
#include "Object.h"
#include "MyJsonHelper.generated.h"
USTRUCT()
struct FCharacterInfo
{
	GENERATED_USTRUCT_BODY()

	UPROPERTY()
		int32 id;
	UPROPERTY()
		FString Name;
	UPROPERTY()
		int32 faction_id;
};
UCLASS()
class TESTJSON_API UMyJsonHelper : public UObject
{
	GENERATED_BODY()	
public:
	UFUNCTION(BlueprintCallable, Category = "My Blueprint Function Library")
	bool ReadJSon(FString &JsonArrayString);
};

.cpp:

#include "JsonObjectConverter.h"
#include "TestJson.h"
#include "MyJsonHelper.h"

bool UMyJsonHelper::ReadJSon(FString &JsonArrayString)
{
	TArray<FCharacterInfo> data;
	return FJsonObjectConverter::JsonArrayStringToUStruct(JsonArrayString, &data, 0, 0);
}

And I have already add the “JsonUtilities” to my build.cs
Below is compiling Error:

Severity Code Description Project File Line Suppression State
Error (active) name followed by ‘::’ must be a class or namespace name TestJson e:\Unreal\TestJson\Source\TestJson\Private\MyJsonHelper.cpp 11

Error MSB3075 The command ““D:\Epic Games\4.12\Engine\Build\BatchFiles\Build.bat” TestJsonEditor Win64 Development “E:\Unreal\TestJson\TestJson.uproject” -waitmutex” exited with code 5. Please verify that you have sufficient rights to run this command. TestJson C:\Program Files
(x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Microsoft.MakeFile.Targets 41

Error (active) cannot open source file “JsonObjectConverter.h” TestJson e:\Unreal\TestJson\Source\TestJson\Private\MyJsonHelper.cpp 4

Error All source files in module “TestJson” must include the same precompiled header first. Currently “E:\Unreal\TestJson\Source\TestJson\TestJson.h” is included by most of the source files. The following source files are not including “E:\Unreal\TestJson\Source\TestJson\TestJson.h” as their first include: TestJson E:\Unreal\TestJson\Intermediate\ProjectFiles\EXEC 1

What am I doing wrong here,Thanks~

I’ve never used that class, but looking at this source file, they used:

#include "Runtime/JsonUtilities/Public/JsonObjectConverter.h"

and, of course, that method is a template method, so you’ll need this at least:

return FJsonObjectConverter::JsonArrayStringToUStruct<FCharacterInfo>(JsonArrayString, &data, 0, 0);
1 Like

Thanks, it really helps me a lot !