Lesson 62 - Parsing the MetaData
This commit is contained in:
@@ -3,9 +3,11 @@
|
||||
|
||||
#include "UI/API_Test/APITestManager.h"
|
||||
#include "HttpModule.h"
|
||||
#include "JsonObjectConverter.h"
|
||||
#include "Data/API/APIData.h"
|
||||
#include "GameplayTags/DedicatedServersTags.h"
|
||||
#include "Interfaces/IHttpResponse.h"
|
||||
#include "UI/HTTP/HTTPRequestTypes.h"
|
||||
|
||||
void UAPITestManager::ListFleetsButtonClicked()
|
||||
{
|
||||
@@ -33,13 +35,12 @@ void UAPITestManager::ListFleets_Response(FHttpRequestPtr Request, FHttpResponse
|
||||
TSharedRef<TJsonReader<>> JsonReader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
|
||||
if (FJsonSerializer::Deserialize(JsonReader, JsonObject))
|
||||
{
|
||||
if (JsonObject->HasField(TEXT("FleetIds")))
|
||||
if (JsonObject->HasField(TEXT("$metadata")))
|
||||
{
|
||||
for (TSharedPtr<FJsonValue> Fleet :JsonObject->GetArrayField(TEXT("FleetIds")))
|
||||
{
|
||||
FString FleetString = Fleet->AsString();
|
||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, FleetString);
|
||||
}
|
||||
TSharedPtr<FJsonObject> MetaDataJsonObject = JsonObject->GetObjectField(TEXT("$metadata"));
|
||||
FDS_MetaData DSMetaData;
|
||||
FJsonObjectConverter::JsonObjectToUStruct(MetaDataJsonObject.ToSharedRef(), &DSMetaData);
|
||||
DSMetaData.Dump();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
11
Source/DedicatedServers/Private/UI/HTTP/HTTPRequestTypes.cpp
Normal file
11
Source/DedicatedServers/Private/UI/HTTP/HTTPRequestTypes.cpp
Normal file
@@ -0,0 +1,11 @@
|
||||
#include "UI/HTTP/HTTPRequestTypes.h"
|
||||
#include "DedicatedServers/DedicatedServers.h"
|
||||
|
||||
void FDS_MetaData::Dump() const
|
||||
{
|
||||
UE_LOGFMT(LogDedicatedServers, Log, "MetaData:");
|
||||
UE_LOGFMT(LogDedicatedServers, Log, "httpStatusCode: {httpStatusCode}", httpStatusCode);
|
||||
UE_LOGFMT(LogDedicatedServers, Log, "requestId: {requestId}", requestId);
|
||||
UE_LOGFMT(LogDedicatedServers, Log, "attemps: {attempts}", attempts);
|
||||
UE_LOGFMT(LogDedicatedServers, Log, "totalRetryDelay: {totalRetryDelay}", totalRetryDelay);
|
||||
}
|
||||
27
Source/DedicatedServers/Private/UI/HTTP/HTTPRequestTypes.h
Normal file
27
Source/DedicatedServers/Private/UI/HTTP/HTTPRequestTypes.h
Normal file
@@ -0,0 +1,27 @@
|
||||
#pragma once
|
||||
|
||||
// Because this is in the private section is is still usable by the DedicatedServer Module, but not outside of the module.
|
||||
|
||||
#include "HTTPRequestTypes.generated.h"
|
||||
|
||||
USTRUCT()
|
||||
struct FDS_MetaData
|
||||
{
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
|
||||
UPROPERTY()
|
||||
int32 httpStatusCode{};
|
||||
|
||||
UPROPERTY()
|
||||
FString requestId{};
|
||||
|
||||
UPROPERTY()
|
||||
int32 attempts{};
|
||||
|
||||
UPROPERTY()
|
||||
double totalRetryDelay{};
|
||||
|
||||
void Dump() const;
|
||||
};
|
||||
Reference in New Issue
Block a user