using
UnrealBuildTool
;
public
class
UE4_Network
:
ModuleRules
public
UE4_Network
(
ReadOnlyTargetRules
Target
)
:
base
(
Target
)
PCHUsage
=
PCHUsageMode
.
UseExplicitOrSharedPCHs
;
PublicDependencyModuleNames
.
AddRange
(
new
string
[]
"Core"
,
"CoreUObject"
,
"Engine"
,
"InputCore"
,
"WebSockets"
,
"Json"
PrivateDependencyModuleNames
.
AddRange
(
new
string
[]
{
});
// Uncomment if you are using Slate UI
// PrivateDependencyModuleNames.AddRange(new string[] { "Slate", "SlateCore" });
// Uncomment if you are using online features
// PrivateDependencyModuleNames.Add("OnlineSubsystem");
// To include OnlineSubsystemSteam, add it to the plugins section in your uproject file with the Enabled attribute set to true
// .cpp
voidAActorWebSocket::OnMessage(constFString&Message)UE_LOG(LogTemp,Warning,TEXT("%s Message:%s"),*FString(__FUNCTION__),*Message);JsonParse(Message);voidAActorWebSocket::JsonParse(constFStringInMessage)TSharedPtr<FJsonObject>RootObj=MakeShareable(newFJsonObject());TSharedRef<TJsonReader<>>JsonReader=TJsonReaderFactory<>::Create(InMessage);if(FJsonSerializer::Deserialize(JsonReader,RootObj))// 通过JsonReader读取RootObj
FStringTopic=RootObj->GetStringField("Topic");// Topic
UE_LOG(LogTemp,Warning,TEXT("%s Topic:%s"),*FString(__FUNCTION__),*Topic);TSharedPtr<FJsonObject>DataObj=MakeShareable(newFJsonObject());DataObj=RootObj->GetObjectField("Data");// Data
FStringKey=DataObj->GetStringField("Key");// Key
UE_LOG(LogTemp,Warning,TEXT("%s Key:%s"),*FString(__FUNCTION__),*Key);if(Key.Equals("Time"))FStringTime=DataObj->GetStringField("Value");// Value type is String
UE_LOG(LogTemp,Warning,TEXT("%s Time:%s"),*FString(__FUNCTION__),*Time);elseif(Key.Equals("Something"))TArray<TSharedPtr<FJsonValue>>Value=DataObj->GetArrayField("Value");// Value type is Array
boolBoolValue=Value[0]->AsBool();intIntValue=Value[1]->AsNumber();floatFloatValue=Value[2]->AsNumber();FStringStringValue=Value[3]->AsString();UE_LOG(LogTemp,Warning,TEXT("%s BoolValue:%d"),*FString(__FUNCTION__),BoolValue);UE_LOG(LogTemp,Warning,TEXT("%s IntValue:%d"),*FString(__FUNCTION__),IntValue);UE_LOG(LogTemp,Warning,TEXT("%s FloatValue:%f"),*FString(__FUNCTION__),FloatValue);UE_LOG(LogTemp,Warning,TEXT("%s StringValue:%s"),*FString(__FUNCTION__),*StringValue);