24 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
28 TSharedRef<FJsonObject>& GetRootObject();
31 void SetRootObject(const TSharedPtr<FJsonObject>& JsonObject);
37 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
38 FString EncodeJson() const;
41 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
42 FString EncodeJsonToSingleString() const;
45 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
46 bool DecodeJson(const FString& JsonString,
bool bUseIncrementalParser = true);
52 UFUNCTION(BlueprintPure, Category = "VaRest|Json")
53 TArray<FString> GetFieldNames() const;
56 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
57 bool HasField(const FString& FieldName) const;
60 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
61 void RemoveField(const FString& FieldName);
64 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
68 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
72 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
76 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
77 void SetArrayField(const FString& FieldName, const TArray<
UVaRestJsonValue*>& InArray);
80 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
88 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
89 float GetNumberField(const FString& FieldName) const;
93 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
94 void SetNumberField(const FString& FieldName,
float Number);
97 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
98 int32 GetIntegerField(const FString& FieldName) const;
101 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
102 void SetIntegerField(const FString& FieldName, int32
Number);
105 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
106 int64 GetInt64Field(const FString& FieldName) const;
109 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
110 void SetInt64Field(const FString& FieldName, int64
Number);
113 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
114 FString GetStringField(const FString& FieldName) const;
117 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
118 void SetStringField(const FString& FieldName, const FString& StringValue);
121 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
122 bool GetBoolField(const FString& FieldName) const;
125 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
126 void SetBoolField(const FString& FieldName,
bool InValue);
129 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
133 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
137 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
138 void SetMapFields_string(const TMap<FString, FString>& Fields);
141 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
142 void SetMapFields_uint8(const TMap<FString, uint8>& Fields);
145 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
146 void SetMapFields_int32(const TMap<FString, int32>& Fields);
149 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
150 void SetMapFields_int64(const TMap<FString, int64>& Fields);
153 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
154 void SetMapFields_bool(const TMap<FString,
bool>& Fields);
158 template <typename T>
159 void SetMapFields_Impl(const TMap<FString, T>& Fields)
161 for (
auto& field : Fields)
164 if (TIsSame<T, uint8>::Value || TIsSame<T, int32>::Value || TIsSame<T, int64>::Value || TIsSame<T, float>::Value)
166 SetNumberField(field.Key, field.Value);
168 else if (TIsSame<T, bool>::Value)
170 SetBoolField(field.Key, (
bool)field.Value);
176 template <
typename T>
177 TArray<T> GetTypeArrayField(
const FString& FieldName)
const
179 TArray<T> NumberArray;
180 if (!JsonObj->HasTypedField<EJson::Array>(FieldName) || FieldName.IsEmpty())
182 UE_LOG(LogVaRest,
Warning, TEXT(
"%s: No field with name %s of type Array"), *
VA_FUNC_LINE, *FieldName);
186 const TArray<TSharedPtr<FJsonValue>> JsonArrayValues = JsonObj->GetArrayField(FieldName);
187 for (TArray<TSharedPtr<FJsonValue>>::TConstIterator It(JsonArrayValues); It; ++It)
189 const auto Value = (*It).Get();
190 if (Value->Type != EJson::Number)
192 UE_LOG(LogVaRest,
Error, TEXT(
"Not Number element in array with field name %s"), *FieldName);
195 NumberArray.Add((*It)->AsNumber());
207 UFUNCTION(BlueprintCallable, Category =
"VaRest|Json")
208 TArray<
float> GetNumberArrayField(const FString& FieldName) const;
211 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
212 TArray<int32> GetIntegerArrayField(const FString& FieldName) const;
216 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
217 void SetNumberArrayField(const FString& FieldName, const TArray<
float>& NumberArray);
220 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
221 TArray<FString> GetStringArrayField(const FString& FieldName) const;
224 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
225 void SetStringArrayField(const FString& FieldName, const TArray<FString>& StringArray);
228 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
229 TArray<
bool> GetBoolArrayField(const FString& FieldName) const;
232 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
233 void SetBoolArrayField(const FString& FieldName, const TArray<
bool>& BoolArray);
236 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
240 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
241 void SetObjectArrayField(const FString& FieldName, const TArray<
UVaRestJsonObject*>& ObjectArray);
248 int32 DeserializeFromUTF8Bytes(const ANSICHAR* Bytes, int32 Size);
251 int32 DeserializeFromTCHARBytes(const TCHAR* Bytes, int32 Size);
254 void DecodeFromArchive(TUniquePtr<FArchive>& Reader);
261 bool WriteToFile(const FString& Path) const;
268 UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
269 bool WriteToFilePath(const FString& Path, const
bool bIsRelativeToProjectDir = true);
271 static
bool WriteStringToArchive(FArchive& Ar, const TCHAR* StrPtr, int64 Len);
278 TSharedRef<FJsonObject> JsonObj;