From f8280b3b473738d091bd9304c3db8bd5b714b1d2 Mon Sep 17 00:00:00 2001 From: Kamil Gronek Date: Thu, 28 Nov 2024 13:08:39 +0100 Subject: [PATCH] Fix bug that membership functions had incorrect checks for JsonObject input. --- .../FunctionLibraries/PubnubJsonUtilities.cpp | 15 ++++++++++++++- .../FunctionLibraries/PubnubJsonUtilities.h | 3 +++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Source/PubnubLibrary/Private/FunctionLibraries/PubnubJsonUtilities.cpp b/Source/PubnubLibrary/Private/FunctionLibraries/PubnubJsonUtilities.cpp index 32df4fb..237eb6e 100644 --- a/Source/PubnubLibrary/Private/FunctionLibraries/PubnubJsonUtilities.cpp +++ b/Source/PubnubLibrary/Private/FunctionLibraries/PubnubJsonUtilities.cpp @@ -23,14 +23,27 @@ bool UPubnubJsonUtilities::StringToJsonObject(FString JsonString, TSharedPtr>& OutArray) +{ + TSharedRef> JsonReader = TJsonReaderFactory::Create(JsonString); + return FJsonSerializer::Deserialize(JsonReader, OutArray); +} + bool UPubnubJsonUtilities::IsCorrectJsonString(const FString InString, bool AllowSimpleTypes) { - //A String is correct Json if it's a valid Json Object or Json Array + //A String is correct Json if it's a valid Json Object TSharedPtr JsonObject = MakeShareable(new FJsonObject); if(StringToJsonObject(InString, JsonObject)) { return true; } + + //or a Json Array + TArray> JsonArray; + if(StringToJsonArray(InString, JsonArray)) + { + return true; + } if(!AllowSimpleTypes) { diff --git a/Source/PubnubLibrary/Public/FunctionLibraries/PubnubJsonUtilities.h b/Source/PubnubLibrary/Public/FunctionLibraries/PubnubJsonUtilities.h index 0c07317..51dfe62 100644 --- a/Source/PubnubLibrary/Public/FunctionLibraries/PubnubJsonUtilities.h +++ b/Source/PubnubLibrary/Public/FunctionLibraries/PubnubJsonUtilities.h @@ -22,6 +22,9 @@ class PUBNUBLIBRARY_API UPubnubJsonUtilities : public UBlueprintFunctionLibrary //Convert FString to JsonObject. Returns true if conversion was successful static bool StringToJsonObject(FString JsonString, TSharedPtr &JsonObject); + //Convert FString to JsonArray. Returns true if conversion was successful + static bool StringToJsonArray(FString JsonString, TArray>& OutArray); + /** * Checks if gives string can be converted to a json * @param InString - String to check