UE4 Json的序列化和反序列化

首先

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "Http", "Json", "JsonUtilities" });

引入头文件

#include "Json.h"

 

//string转json
TSharedPtr<FJsonObject> MessageObject = MakeShareable(new FJsonObject);
TSharedRef< TJsonReader<> > Reader = TJsonReaderFactory<>::Create(MessageBody);
FJsonSerializer::Deserialize(Reader, MessageObject);


//Json转string
FString TempStr;
TSharedRef<TJsonWriter<>> Writer = TJsonWriterFactory<>::Create(&TempStr);
FJsonSerializer::Serialize(MessageObject.ToSharedRef(), Writer);

 

©️2020 CSDN 皮肤主题: 技术黑板 设计师:CSDN官方博客 返回首页