This repository has been archived by the owner on May 3, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #19 from AaronShea/feature/jsonObj
merge feature/json obj
- Loading branch information
Showing
6 changed files
with
136 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
#include "BluPrivatePCH.h" | ||
#include "Json.h" | ||
|
||
UBluJsonObj::UBluJsonObj(const class FObjectInitializer& PCIP) | ||
: Super(PCIP) | ||
{ | ||
|
||
} | ||
|
||
void UBluJsonObj::init(const FString &StringData) | ||
{ | ||
|
||
StrData = *StringData; | ||
|
||
TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(StringData); | ||
doParseJson(JsonReader); | ||
|
||
} | ||
|
||
FString UBluJsonObj::getStringValue(const FString &index) | ||
{ | ||
|
||
return JsonParsed->GetStringField(index); | ||
|
||
} | ||
|
||
bool UBluJsonObj::getBooleanValue(const FString &index) | ||
{ | ||
|
||
return JsonParsed->GetBoolField(index); | ||
|
||
} | ||
|
||
float UBluJsonObj::getNumValue(const FString &index) | ||
{ | ||
|
||
return JsonParsed->GetNumberField(index); | ||
|
||
} | ||
|
||
UBluJsonObj* UBluJsonObj::getNestedObject(const FString &index) | ||
{ | ||
|
||
TSharedPtr<FJsonObject> newJson = JsonParsed->GetObjectField(index); | ||
|
||
if (!newJson.IsValid()) | ||
{ | ||
return NULL; | ||
} | ||
|
||
// Make our new temp obj | ||
UBluJsonObj* tempObj = NewObject<UBluJsonObj>(GetTransientPackage(), UBluJsonObj::StaticClass()); | ||
tempObj->setJsonObj(newJson); | ||
|
||
// return it | ||
return tempObj; | ||
|
||
} | ||
|
||
void UBluJsonObj::setJsonObj(TSharedPtr<FJsonObject> NewJson) | ||
{ | ||
|
||
// Set our new stored JSON object | ||
JsonParsed = NewJson; | ||
|
||
} | ||
|
||
void UBluJsonObj::doParseJson(TSharedRef<TJsonReader<TCHAR>> JsonReader) | ||
{ | ||
|
||
if (!FJsonSerializer::Deserialize(JsonReader, JsonParsed)) | ||
{ | ||
UE_LOG(LogBlu, Warning, TEXT("JSON STRING FAILED TO PARSE! WILL DEFAULT TO EMPTY OBJECT {}")); | ||
|
||
// Make an empty json object to prevent crashing | ||
doParseJson(TJsonReaderFactory<TCHAR>::Create("{}")); | ||
} | ||
|
||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
#pragma once | ||
|
||
#include "BluJsonObj.generated.h" | ||
|
||
UCLASS(ClassGroup = Blu, Blueprintable) | ||
class BLU_API UBluJsonObj : public UObject | ||
{ | ||
|
||
GENERATED_UCLASS_BODY() | ||
|
||
public: | ||
|
||
UFUNCTION(BlueprintCallable, Category = "Blu") | ||
FString getStringValue(const FString &index); | ||
|
||
UFUNCTION(BlueprintCallable, Category = "Blu") | ||
float getNumValue(const FString &index); | ||
|
||
UFUNCTION(BlueprintCallable, Category = "Blu") | ||
bool getBooleanValue(const FString &index); | ||
|
||
UFUNCTION(BlueprintCallable, Category = "Blu") | ||
UBluJsonObj* getNestedObject(const FString &index); | ||
|
||
void init(const FString &dataString); | ||
void setJsonObj(TSharedPtr<FJsonObject> NewJson); | ||
|
||
private: | ||
|
||
FString StrData; | ||
TSharedPtr<FJsonObject> JsonParsed; | ||
|
||
void doParseJson(TSharedRef<TJsonReader<TCHAR>> JsonReader); | ||
|
||
|
||
}; |