1、在[Project].Build.cs文件中添加Module
添加Json这个module
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "Json"});
2、解析
FString jsonStr;
bool result = FFileHelper::LoadFileToString(jsonStr, fullPath.GetCharArray().GetData(), FFileHelper::EHashOptions::None, 0);
//GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Orange, FString::Printf(TEXT("jsonStr is: %s"), *jsonStr));
TSharedPtr<FJsonObject> jsonObject = MakeShareable(new FJsonObject);
TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(jsonStr);
if (!FJsonSerializer::Deserialize(Reader, jsonObject))
{
UE_LOG(LogTemp, Error, TEXT("JSON_PARSE_FAIL"));
return;
}
else
{
this->name = jsonObject->GetStringField("name");
//GEngine->AddOnScreenDebu