Lesson 61 - Parsing an HTTP Response

This commit is contained in:
Norman Lansing
2026-03-15 22:09:50 -04:00
parent 3912fe52c6
commit 8d6f3f68f1
2 changed files with 18 additions and 1 deletions

View File

@@ -24,7 +24,9 @@ public class DedicatedServers : ModuleRules
"Slate",
"SlateCore",
"OpenSSL",
"UMG"
"UMG",
"Json",
"JsonUtilities"
});
// Adds in the plugin for GameLiftServerSDK if it is the server build.

View File

@@ -5,6 +5,7 @@
#include "HttpModule.h"
#include "Data/API/APIData.h"
#include "GameplayTags/DedicatedServersTags.h"
#include "Interfaces/IHttpResponse.h"
void UAPITestManager::ListFleetsButtonClicked()
{
@@ -27,4 +28,18 @@ void UAPITestManager::ListFleetsButtonClicked()
void UAPITestManager::ListFleets_Response(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
{
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, "List Fleets Response Received");
TSharedPtr<FJsonObject> JsonObject;
TSharedRef<TJsonReader<>> JsonReader = TJsonReaderFactory<>::Create(Response->GetContentAsString());
if (FJsonSerializer::Deserialize(JsonReader, JsonObject))
{
if (JsonObject->HasField(TEXT("FleetIds")))
{
for (TSharedPtr<FJsonValue> Fleet :JsonObject->GetArrayField(TEXT("FleetIds")))
{
FString FleetString = Fleet->AsString();
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, FleetString);
}
}
}
}