Lesson 61 - Parsing an HTTP Response
This commit is contained in:
@@ -24,7 +24,9 @@ public class DedicatedServers : ModuleRules
|
|||||||
"Slate",
|
"Slate",
|
||||||
"SlateCore",
|
"SlateCore",
|
||||||
"OpenSSL",
|
"OpenSSL",
|
||||||
"UMG"
|
"UMG",
|
||||||
|
"Json",
|
||||||
|
"JsonUtilities"
|
||||||
});
|
});
|
||||||
|
|
||||||
// Adds in the plugin for GameLiftServerSDK if it is the server build.
|
// Adds in the plugin for GameLiftServerSDK if it is the server build.
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
#include "HttpModule.h"
|
#include "HttpModule.h"
|
||||||
#include "Data/API/APIData.h"
|
#include "Data/API/APIData.h"
|
||||||
#include "GameplayTags/DedicatedServersTags.h"
|
#include "GameplayTags/DedicatedServersTags.h"
|
||||||
|
#include "Interfaces/IHttpResponse.h"
|
||||||
|
|
||||||
void UAPITestManager::ListFleetsButtonClicked()
|
void UAPITestManager::ListFleetsButtonClicked()
|
||||||
{
|
{
|
||||||
@@ -27,4 +28,18 @@ void UAPITestManager::ListFleetsButtonClicked()
|
|||||||
void UAPITestManager::ListFleets_Response(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
|
void UAPITestManager::ListFleets_Response(FHttpRequestPtr Request, FHttpResponsePtr Response, bool bWasSuccessful)
|
||||||
{
|
{
|
||||||
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Blue, "List Fleets Response Received");
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user