Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
void AFileLoad::BeginPlay(){
Super::BeginPlay();
// Load
FString aFullPath = FPaths::GameSavedDir();
aFullPath += "example.json";
FString JsonStr;
FFileHelper::LoadFileToString(JsonStr, *aFullPath);
if (GEngine){
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, JsonStr);
}
// JsonReader! ===================================
TSharedRef<TJsonReader<TCHAR>> JsonReader = TJsonReaderFactory<TCHAR>::Create(JsonStr);
TSharedPtr<FJsonObject> JsonObject = MakeShareable(new FJsonObject());
if (FJsonSerializer::Deserialize(JsonReader, JsonObject) && JsonObject.IsValid())
{
if (GEngine){
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Deserialize"));
}
// Entries Array Get
//TArray<TSharedPtr<FJsonValue>> objArray = JsonObject->GetArrayField(TEXT("Entries"));
TArray<TSharedPtr<FJsonValue>> objArray = JsonObject->GetArrayField(TEXT("Entries"));
for (int32 i = 0; i < objArray.Num(); i++)
{
TSharedPtr<FJsonValue> value = objArray[i];
TSharedPtr<FJsonObject> json = value->AsObject();
FString name = json->GetStringField(TEXT("Name"));
FString bc = json->GetStringField(TEXT("BC"));
FString ln = json->GetStringField(TEXT("LN"));
FString rt = json->GetStringField(TEXT("RT"));
FString sc = json->GetStringField(TEXT("SC"));
if (GEngine){
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("json:"));
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, name);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, bc);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, ln);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, rt);
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, sc);
}
}
}
else{
if (GEngine){
GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Yellow, TEXT("Not Deserialize"));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment