A Demo Project for the UnrealEngineSDK
Loading...
Searching...
No Matches
VaRestJsonObject.cpp
Go to the documentation of this file.
1// Copyright 2014-2019 Vladimir Alyamkin. All Rights Reserved.
2
3#include "VaRestJsonObject.h"
4
5#include "VaRestDefines.h"
6#include "VaRestJsonParser.h"
7#include "VaRestJsonValue.h"
8
9#include "Runtime/Launch/Resources/Version.h"
10
11typedef TJsonWriterFactory<TCHAR, TCondensedJsonPrintPolicy<TCHAR>> FCondensedJsonStringWriterFactory;
12typedef TJsonWriter<TCHAR, TCondensedJsonPrintPolicy<TCHAR>> FCondensedJsonStringWriter;
13
14UVaRestJsonObject::UVaRestJsonObject(const FObjectInitializer& ObjectInitializer)
15 : Super(ObjectInitializer)
16 , JsonObj(MakeShared<FJsonObject>())
17{
18}
19
24
25TSharedRef<FJsonObject>& UVaRestJsonObject::GetRootObject()
26{
27 return JsonObj;
28}
29
30void UVaRestJsonObject::SetRootObject(const TSharedPtr<FJsonObject>& JsonObject)
31{
32 if (JsonObject.IsValid())
33 {
34 JsonObj = JsonObject.ToSharedRef();
35 }
36 else
37 {
38 UE_LOG(LogVaRest, Error, TEXT("%s: Trying to set invalid json object as root one. Reset now."), *VA_FUNC_LINE);
39 Reset();
40 }
41}
42
44// Serialization
45
47{
48 FString OutputString;
49 const auto Writer = TJsonWriterFactory<>::Create(&OutputString);
50 FJsonSerializer::Serialize(JsonObj, Writer);
51
52 return OutputString;
53}
54
56{
57 FString OutputString;
58 const auto Writer = FCondensedJsonStringWriterFactory::Create(&OutputString);
59 FJsonSerializer::Serialize(JsonObj, Writer);
60
61 return OutputString;
62}
63
64bool UVaRestJsonObject::DecodeJson(const FString& JsonString, bool bUseIncrementalParser)
65{
67 {
68 const int32 BytesRead = DeserializeFromTCHARBytes(JsonString.GetCharArray().GetData(), JsonString.Len());
69
70 // JsonObj is always valid, but read bytes is zero when something went wrong
71 if (BytesRead > 0)
72 {
73 return true;
74 }
75 }
76 else
77 {
78 const TSharedRef<TJsonReader<>> Reader = TJsonReaderFactory<>::Create(*JsonString);
79 TSharedPtr<FJsonObject> OutJsonObj;
80 if (FJsonSerializer::Deserialize(Reader, OutJsonObj))
81 {
82 JsonObj = OutJsonObj.ToSharedRef();
83 return true;
84 }
85 }
86
87 // If we've failed to deserialize the string, we should clear our internal data
88 Reset();
89
90 UE_LOG(LogVaRest, Error, TEXT("Json decoding failed for: %s"), *JsonString);
91
92 return false;
93}
94
96// FJsonObject API
97
98TArray<FString> UVaRestJsonObject::GetFieldNames() const
99{
100 TArray<FString> Result;
101 JsonObj->Values.GetKeys(Result);
102
103 return Result;
104}
105
106bool UVaRestJsonObject::HasField(const FString& FieldName) const
107{
108 if (FieldName.IsEmpty())
109 {
110 return false;
111 }
112
113 return JsonObj->HasField(FieldName);
114}
115
116void UVaRestJsonObject::RemoveField(const FString& FieldName)
117{
118 if (FieldName.IsEmpty())
119 {
120 return;
121 }
122
123 JsonObj->RemoveField(FieldName);
124}
125
126UVaRestJsonValue* UVaRestJsonObject::GetField(const FString& FieldName) const
127{
128 if (FieldName.IsEmpty())
129 {
130 return nullptr;
131 }
132
133 TSharedPtr<FJsonValue> NewVal = JsonObj->TryGetField(FieldName);
134 if (NewVal.IsValid())
135 {
137 NewValue->SetRootValue(NewVal);
138
139 return NewValue;
140 }
141
142 return nullptr;
143}
144
145void UVaRestJsonObject::SetField(const FString& FieldName, UVaRestJsonValue* JsonValue)
146{
147 if (FieldName.IsEmpty())
148 {
149 return;
150 }
151
152 JsonObj->SetField(FieldName, JsonValue->GetRootValue());
153}
154
156// FJsonObject API Helpers (easy to use with simple Json objects)
157
158float UVaRestJsonObject::GetNumberField(const FString& FieldName) const
159{
160 if (!JsonObj->HasTypedField<EJson::Number>(FieldName))
161 {
162 UE_LOG(LogVaRest, Warning, TEXT("No field with name %s of type Number"), *FieldName);
163 return 0.0f;
164 }
165
166 return JsonObj->GetNumberField(FieldName);
167}
168
169void UVaRestJsonObject::SetNumberField(const FString& FieldName, float Number)
170{
171 if (FieldName.IsEmpty())
172 {
173 return;
174 }
175
176 JsonObj->SetNumberField(FieldName, Number);
177}
178
179int32 UVaRestJsonObject::GetIntegerField(const FString& FieldName) const
180{
181 if (!JsonObj->HasTypedField<EJson::Number>(FieldName))
182 {
183 UE_LOG(LogVaRest, Warning, TEXT("No field with name %s of type Number"), *FieldName);
184 return 0;
185 }
186
187 return JsonObj->GetIntegerField(FieldName);
188}
189
190void UVaRestJsonObject::SetIntegerField(const FString& FieldName, int32 Number)
191{
192 if (FieldName.IsEmpty())
193 {
194 return;
195 }
196
197 JsonObj->SetNumberField(FieldName, Number);
198}
199
200int64 UVaRestJsonObject::GetInt64Field(const FString& FieldName) const
201{
202 if (!JsonObj->HasTypedField<EJson::Number>(FieldName))
203 {
204 UE_LOG(LogVaRest, Warning, TEXT("No field with name %s of type Number"), *FieldName);
205 return 0;
206 }
207
208 return static_cast<int64>(JsonObj->GetNumberField(FieldName));
209}
210
211void UVaRestJsonObject::SetInt64Field(const FString& FieldName, int64 Number)
212{
213 if (FieldName.IsEmpty())
214 {
215 return;
216 }
217
218 JsonObj->SetNumberField(FieldName, Number);
219}
220
221FString UVaRestJsonObject::GetStringField(const FString& FieldName) const
222{
223 if (!JsonObj->HasTypedField<EJson::String>(FieldName))
224 {
225 UE_LOG(LogVaRest, Warning, TEXT("No field with name %s of type String"), *FieldName);
226 return TEXT("");
227 }
228
229 return JsonObj->GetStringField(FieldName);
230}
231
232void UVaRestJsonObject::SetStringField(const FString& FieldName, const FString& StringValue)
233{
234 if (FieldName.IsEmpty())
235 {
236 return;
237 }
238
239 JsonObj->SetStringField(FieldName, StringValue);
240}
241
242bool UVaRestJsonObject::GetBoolField(const FString& FieldName) const
243{
244 if (!JsonObj->HasTypedField<EJson::Boolean>(FieldName))
245 {
246 UE_LOG(LogVaRest, Warning, TEXT("No field with name %s of type Boolean"), *FieldName);
247 return false;
248 }
249
250 return JsonObj->GetBoolField(FieldName);
251}
252
253void UVaRestJsonObject::SetBoolField(const FString& FieldName, bool InValue)
254{
255 if (FieldName.IsEmpty())
256 {
257 return;
258 }
259
260 JsonObj->SetBoolField(FieldName, InValue);
261}
262
263TArray<UVaRestJsonValue*> UVaRestJsonObject::GetArrayField(const FString& FieldName) const
264{
266 if (FieldName.IsEmpty())
267 {
268 return OutArray;
269 }
270
271 if (!JsonObj->HasTypedField<EJson::Array>(FieldName))
272 {
273 UE_LOG(LogVaRest, Warning, TEXT("%s: No field with name %s of type Array"), *VA_FUNC_LINE, *FieldName);
274 return OutArray;
275 }
276
278 for (auto Value : ValArray)
279 {
281 NewValue->SetRootValue(Value);
282
283 OutArray.Add(NewValue);
284 }
285
286 return OutArray;
287}
288
289void UVaRestJsonObject::SetArrayField(const FString& FieldName, const TArray<UVaRestJsonValue*>& InArray)
290{
291 if (FieldName.IsEmpty())
292 {
293 return;
294 }
295
297
298 // Process input array and COPY original values
299 for (auto InVal : InArray)
300 {
301 const TSharedPtr<FJsonValue> JsonVal = InVal->GetRootValue();
302
303 switch (InVal->GetType())
304 {
305 case EVaJson::None:
306 break;
307
308 case EVaJson::Null:
310 break;
311
312 case EVaJson::String:
313 ValArray.Add(MakeShareable(new FJsonValueString(JsonVal->AsString())));
314 break;
315
316 case EVaJson::Number:
317 ValArray.Add(MakeShareable(new FJsonValueNumber(JsonVal->AsNumber())));
318 break;
319
320 case EVaJson::Boolean:
321 ValArray.Add(MakeShareable(new FJsonValueBoolean(JsonVal->AsBool())));
322 break;
323
324 case EVaJson::Array:
325 ValArray.Add(MakeShareable(new FJsonValueArray(JsonVal->AsArray())));
326 break;
327
328 case EVaJson::Object:
329 ValArray.Add(MakeShareable(new FJsonValueObject(JsonVal->AsObject())));
330 break;
331
332 default:
333 break;
334 }
335 }
336
337 JsonObj->SetArrayField(FieldName, ValArray);
338}
339
340void UVaRestJsonObject::MergeJsonObject(UVaRestJsonObject* InJsonObject, bool Overwrite)
341{
342 if (!InJsonObject || !InJsonObject->IsValidLowLevel())
343 {
344 return;
345 }
346
347 TArray<FString> Keys = InJsonObject->GetFieldNames();
348
349 for (auto Key : Keys)
350 {
351 if (Overwrite == false && HasField(Key))
352 {
353 continue;
354 }
355
356 SetField(Key, InJsonObject->GetField(Key));
357 }
358}
359
361{
362 if (!JsonObj->HasTypedField<EJson::Object>(FieldName))
363 {
364 UE_LOG(LogVaRest, Warning, TEXT("%s: No field with name %s of type Object"), *VA_FUNC_LINE, *FieldName);
365 return nullptr;
366 }
367
368 const TSharedPtr<FJsonObject> JsonObjField = JsonObj->GetObjectField(FieldName);
369
371 OutRestJsonObj->SetRootObject(JsonObjField);
372
373 return OutRestJsonObj;
374}
375
376void UVaRestJsonObject::SetObjectField(const FString& FieldName, UVaRestJsonObject* JsonObject)
377{
378 if (FieldName.IsEmpty() || !JsonObject || !JsonObject->IsValidLowLevel())
379 {
380 return;
381 }
382
383 JsonObj->SetObjectField(FieldName, JsonObject->GetRootObject());
384}
385
386void UVaRestJsonObject::SetMapFields_string(const TMap<FString, FString>& Fields)
387{
388 for (auto& field : Fields)
389 {
390 SetStringField(field.Key, field.Value);
391 }
392}
393
394void UVaRestJsonObject::SetMapFields_uint8(const TMap<FString, uint8>& Fields)
395{
396 SetMapFields_Impl(Fields);
397}
398
399void UVaRestJsonObject::SetMapFields_int32(const TMap<FString, int32>& Fields)
400{
401 SetMapFields_Impl(Fields);
402}
403
404void UVaRestJsonObject::SetMapFields_int64(const TMap<FString, int64>& Fields)
405{
406 SetMapFields_Impl(Fields);
407}
408
409void UVaRestJsonObject::SetMapFields_bool(const TMap<FString, bool>& Fields)
410{
411 SetMapFields_Impl(Fields);
412}
413
415// Array fields helpers (uniform arrays)
416
417TArray<float> UVaRestJsonObject::GetNumberArrayField(const FString& FieldName) const
418{
420}
421
422TArray<int32> UVaRestJsonObject::GetIntegerArrayField(const FString& FieldName) const
423{
425}
426
427void UVaRestJsonObject::SetNumberArrayField(const FString& FieldName, const TArray<float>& NumberArray)
428{
429 if (FieldName.IsEmpty())
430 {
431 return;
432 }
433
435
436 for (auto Number : NumberArray)
437 {
439 }
440
441 JsonObj->SetArrayField(FieldName, EntriesArray);
442}
443
444TArray<FString> UVaRestJsonObject::GetStringArrayField(const FString& FieldName) const
445{
446 TArray<FString> StringArray;
447 if (!JsonObj->HasTypedField<EJson::Array>(FieldName) || FieldName.IsEmpty())
448 {
449 UE_LOG(LogVaRest, Warning, TEXT("%s: No field with name %s of type Array"), *VA_FUNC_LINE, *FieldName);
450 return StringArray;
451 }
452
454 for (TArray<TSharedPtr<FJsonValue>>::TConstIterator It(JsonArrayValues); It; ++It)
455 {
456 const auto Value = (*It).Get();
457 if (Value->Type != EJson::String)
458 {
459 UE_LOG(LogVaRest, Error, TEXT("Not String element in array with field name %s"), *FieldName);
460 }
461
462 StringArray.Add((*It)->AsString());
463 }
464
465 return StringArray;
466}
467
468void UVaRestJsonObject::SetStringArrayField(const FString& FieldName, const TArray<FString>& StringArray)
469{
470 if (FieldName.IsEmpty())
471 {
472 return;
473 }
474
476 for (auto String : StringArray)
477 {
479 }
480
481 JsonObj->SetArrayField(FieldName, EntriesArray);
482}
483
484TArray<bool> UVaRestJsonObject::GetBoolArrayField(const FString& FieldName) const
485{
486 TArray<bool> BoolArray;
487 if (!JsonObj->HasTypedField<EJson::Array>(FieldName) || FieldName.IsEmpty())
488 {
489 UE_LOG(LogVaRest, Warning, TEXT("%s: No field with name %s of type Array"), *VA_FUNC_LINE, *FieldName);
490 return BoolArray;
491 }
492
494 for (TArray<TSharedPtr<FJsonValue>>::TConstIterator It(JsonArrayValues); It; ++It)
495 {
496 const auto Value = (*It).Get();
497 if (Value->Type != EJson::Boolean)
498 {
499 UE_LOG(LogVaRest, Error, TEXT("Not Boolean element in array with field name %s"), *FieldName);
500 }
501
502 BoolArray.Add((*It)->AsBool());
503 }
504
505 return BoolArray;
506}
507
508void UVaRestJsonObject::SetBoolArrayField(const FString& FieldName, const TArray<bool>& BoolArray)
509{
510 if (FieldName.IsEmpty())
511 {
512 return;
513 }
514
516 for (auto Boolean : BoolArray)
517 {
519 }
520
521 JsonObj->SetArrayField(FieldName, EntriesArray);
522}
523
524TArray<UVaRestJsonObject*> UVaRestJsonObject::GetObjectArrayField(const FString& FieldName) const
525{
527 if (!JsonObj->HasTypedField<EJson::Array>(FieldName) || FieldName.IsEmpty())
528 {
529 UE_LOG(LogVaRest, Warning, TEXT("%s: No field with name %s of type Array"), *VA_FUNC_LINE, *FieldName);
530 return OutArray;
531 }
532
534 for (const auto& Value : ValArray)
535 {
536 if (Value->Type != EJson::Object)
537 {
538 UE_LOG(LogVaRest, Error, TEXT("Not Object element in array with field name %s"), *FieldName);
539 }
540
541 TSharedPtr<FJsonObject> NewObj = Value->AsObject();
542
544 NewJson->SetRootObject(NewObj);
545
546 OutArray.Add(NewJson);
547 }
548
549 return OutArray;
550}
551
552void UVaRestJsonObject::SetObjectArrayField(const FString& FieldName, const TArray<UVaRestJsonObject*>& ObjectArray)
553{
554 if (FieldName.IsEmpty())
555 {
556 return;
557 }
558
560 for (auto Value : ObjectArray)
561 {
562 EntriesArray.Add(MakeShareable(new FJsonValueObject(Value->GetRootObject())));
563 }
564
565 JsonObj->SetArrayField(FieldName, EntriesArray);
566}
567
569// Deserialize
570
571int32 UVaRestJsonObject::DeserializeFromUTF8Bytes(const ANSICHAR* Bytes, int32 Size)
572{
574
575 const ANSICHAR* EndByte = Bytes + Size;
576 while (Bytes < EndByte)
577 {
579 if (Char > 0xFFFF)
580 {
582 }
583
584 if (!Reader.Read(Char))
585 {
586 break;
587 }
588 }
589
590 SetRootObject(Reader.State.Root);
591 return Reader.State.Size;
592}
593
594int32 UVaRestJsonObject::DeserializeFromTCHARBytes(const TCHAR* Bytes, int32 Size)
595{
597
598 int32 i = 0;
599 while (i < Size)
600 {
601 if (!Reader.Read(Bytes[i++]))
602 {
603 break;
604 }
605 }
606
607 SetRootObject(Reader.State.Root);
608 return Reader.State.Size;
609}
610
611void UVaRestJsonObject::DecodeFromArchive(TUniquePtr<FArchive>& Reader)
612{
613 FArchive& Ar = (*Reader.Get());
614 uint8 SymbolBytes[2];
615
616 // Read first two bytes
617 Ar << SymbolBytes[0];
618 Ar << SymbolBytes[1];
619
620 bool bIsIntelByteOrder = true;
621
622 if (SymbolBytes[0] == 0xff && SymbolBytes[1] == 0xfe)
623 {
624 // Unicode Intel byte order. Less 1 for the FFFE header, additional 1 for null terminator.
625 bIsIntelByteOrder = true;
626 }
627 else if (SymbolBytes[0] == 0xfe && SymbolBytes[1] == 0xff)
628 {
629 // Unicode non-Intel byte order. Less 1 for the FFFE header, additional 1 for null terminator.
630 bIsIntelByteOrder = false;
631 }
632
634 TCHAR Char;
635
636 while (!Ar.AtEnd())
637 {
638 Ar << SymbolBytes[0];
639
640 if (Ar.AtEnd())
641 {
642 break;
643 }
644
645 Ar << SymbolBytes[1];
646
648 {
649 Char = CharCast<TCHAR>(static_cast<UCS2CHAR>(static_cast<uint16>(SymbolBytes[0]) + static_cast<uint16>(SymbolBytes[1]) * 256));
650 }
651 else
652 {
653 Char = CharCast<TCHAR>(static_cast<UCS2CHAR>(static_cast<uint16>(SymbolBytes[1]) + static_cast<uint16>(SymbolBytes[0]) * 256));
654 }
655
656 if (!JsonReader.Read(Char))
657 {
658 break;
659 }
660 }
661
662 SetRootObject(JsonReader.State.Root);
663
664 if (!Ar.Close())
665 {
666 UE_LOG(LogVaRest, Error, TEXT("UVaRestJsonObject::DecodeFromArchive: Error! Can't close file!"));
667 }
668}
669
671// Serialize
672
673bool UVaRestJsonObject::WriteToFile(const FString& Path) const
674{
675 TUniquePtr<FArchive> FileWriter(IFileManager::Get().CreateFileWriter(*Path));
676 if (!FileWriter)
677 {
678 return false;
679 }
680
681 FArchive& Ar = *FileWriter.Get();
682
684 Ar.Serialize(&BOM, sizeof(UCS2CHAR));
685
686 FString Str = FString(TEXT("{"));
687 WriteStringToArchive(Ar, *Str, Str.Len());
688
689 int32 ElementCount = 0;
691 for (auto JsonObjectValuePair : JsonObj->Values)
692 {
693 Str = FString(TEXT("\""));
694 WriteStringToArchive(Ar, *Str, Str.Len());
695
696 const TCHAR* BufferPtr = *JsonObjectValuePair.Key;
697 for (int i = 0; i < JsonObjectValuePair.Key.Len(); ++i)
698 {
699 Str = FString(1, &BufferPtr[i]);
700 WriteStringToArchive(Ar, *Str, Str.Len());
701 }
702
703 Str = FString(TEXT("\""));
704 WriteStringToArchive(Ar, *Str, Str.Len());
705
706 Str = FString(TEXT(":"));
707 WriteStringToArchive(Ar, *Str, Str.Len());
708
709 ++ElementCount;
710
711 JsonWriter.Write(JsonObjectValuePair.Value, FileWriter.Get(), ElementCount >= JsonObj->Values.Num());
712 }
713
714 Str = FString(TEXT("}"));
715 WriteStringToArchive(Ar, *Str, Str.Len());
716
717 FileWriter->Close();
718
719 return true;
720}
721
722bool UVaRestJsonObject::WriteToFilePath(const FString& Path, const bool bIsRelativeToProjectDir)
723{
724 return WriteToFile(bIsRelativeToProjectDir ? FPaths::ProjectDir() / Path : Path);
725}
726
727bool UVaRestJsonObject::WriteStringToArchive(FArchive& Ar, const TCHAR* StrPtr, int64 Len)
728{
729 const auto Src = StringCast<UCS2CHAR>(StrPtr, Len);
730 Ar.Serialize(const_cast<UCS2CHAR*>(Src.Get()), Src.Length() * sizeof(UCS2CHAR));
731
732 return true;
733}
#define VA_FUNC_LINE
TJsonWriter< TCHAR, TCondensedJsonPrintPolicy< TCHAR > > FCondensedJsonStringWriter
TJsonWriterFactory< TCHAR, TCondensedJsonPrintPolicy< TCHAR > > FCondensedJsonStringWriterFactory
UCLASS(BlueprintType, Blueprintable)
void SetObjectField(const FString &FieldName, UVaRestJsonObject *JsonObject)
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
static bool WriteStringToArchive(FArchive &Ar, const TCHAR *StrPtr, int64 Len)
UVaRestJsonValue * GetField(const FString &FieldName) const
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
TArray< bool > GetBoolArrayField(const FString &FieldName) const
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
bool WriteToFile(const FString &Path) const
void RemoveField(const FString &FieldName)
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
TArray< T > GetTypeArrayField(const FString &FieldName) const
int32 DeserializeFromTCHARBytes(const TCHAR *Bytes, int32 Size)
TArray< float > GetNumberArrayField(const FString &FieldName) const
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
TSharedRef< FJsonObject > & GetRootObject()
void SetRootObject(const TSharedPtr< FJsonObject > &JsonObject)
UVaRestJsonObject * GetObjectField(const FString &FieldName) const
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
FString EncodeJson() const
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
void SetMapFields_uint8(const TMap< FString, uint8 > &Fields)
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
void SetIntegerField(const FString &FieldName, int32 Number)
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
void DecodeFromArchive(TUniquePtr< FArchive > &Reader)
void SetMapFields_string(const TMap< FString, FString > &Fields)
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
void SetObjectArrayField(const FString &FieldName, const TArray< UVaRestJsonObject * > &ObjectArray)
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
void SetNumberArrayField(const FString &FieldName, const TArray< float > &NumberArray)
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
TArray< FString > GetStringArrayField(const FString &FieldName) const
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
int64 GetInt64Field(const FString &FieldName) const
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
void Reset()
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
FString EncodeJsonToSingleString() const
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
void SetInt64Field(const FString &FieldName, int64 Number)
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
int32 DeserializeFromUTF8Bytes(const ANSICHAR *Bytes, int32 Size)
void SetStringField(const FString &FieldName, const FString &StringValue)
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
void SetMapFields_int32(const TMap< FString, int32 > &Fields)
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
void SetBoolField(const FString &FieldName, bool InValue)
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
void MergeJsonObject(UVaRestJsonObject *InJsonObject, bool Overwrite)
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
TArray< int32 > GetIntegerArrayField(const FString &FieldName) const
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
bool HasField(const FString &FieldName) const
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
TArray< UVaRestJsonObject * > GetObjectArrayField(const FString &FieldName) const
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
TArray< FString > GetFieldNames() const
UFUNCTION(BlueprintPure, Category = "VaRest|Json")
bool WriteToFilePath(const FString &Path, const bool bIsRelativeToProjectDir=true)
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
TArray< UVaRestJsonValue * > GetArrayField(const FString &FieldName) const
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
void SetMapFields_int64(const TMap< FString, int64 > &Fields)
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
void SetField(const FString &FieldName, UVaRestJsonValue *JsonValue)
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
void SetMapFields_bool(const TMap< FString, bool > &Fields)
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
int32 GetIntegerField(const FString &FieldName) const
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
float GetNumberField(const FString &FieldName) const
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
void SetBoolArrayField(const FString &FieldName, const TArray< bool > &BoolArray)
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
void SetNumberField(const FString &FieldName, float Number)
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
TSharedRef< FJsonObject > JsonObj
bool DecodeJson(const FString &JsonString, bool bUseIncrementalParser=true)
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
void SetArrayField(const FString &FieldName, const TArray< UVaRestJsonValue * > &InArray)
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
bool GetBoolField(const FString &FieldName) const
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
void SetMapFields_Impl(const TMap< FString, T > &Fields)
void SetStringArrayField(const FString &FieldName, const TArray< FString > &StringArray)
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
FString GetStringField(const FString &FieldName) const
UFUNCTION(BlueprintCallable, Category = "VaRest|Json")
UCLASS(BlueprintType, Blueprintable)
void SetRootValue(TSharedPtr< FJsonValue > &JsonValue)
TSharedPtr< FJsonValue > & GetRootValue()
static uint32 CodepointFromUtf8(const ANSICHAR *&SourceString, const uint32 SourceLengthRemaining)