bool FDataTableExporterJSON::WriteStruct(const UScriptStruct* InStruct, const void* InStructData) { for (TFieldIterator<const UProperty> It(InStruct); It; ++It) { const UProperty* BaseProp = *It; check(BaseProp); if (BaseProp->ArrayDim == 1) { const void* Data = BaseProp->ContainerPtrToValuePtr<void>(InStructData, 0); WriteStructEntry(InStructData, BaseProp, Data); } else { const FString Identifier = DataTableUtils::GetPropertyExportName(BaseProp, DTExportFlags); JsonWriter->WriteArrayStart(Identifier); for (int32 ArrayEntryIndex = 0; ArrayEntryIndex < BaseProp->ArrayDim; ++ArrayEntryIndex) { const void* Data = BaseProp->ContainerPtrToValuePtr<void>(InStructData, ArrayEntryIndex); WriteArrayEntry(BaseProp, Data); } JsonWriter->WriteArrayEnd(); } } return true; }
bool FDataTableExporterJSON::WriteStructEntry(const void* InRowData, const UProperty* InProperty, const void* InPropertyData) { if (const UNumericProperty *NumProp = Cast<const UNumericProperty>(InProperty)) { if (NumProp->IsInteger()) { const int64 PropertyValue = NumProp->GetSignedIntPropertyValue(InPropertyData); JsonWriter->WriteValue(InProperty->GetName(), PropertyValue); } else { const double PropertyValue = NumProp->GetFloatingPointPropertyValue(InPropertyData); JsonWriter->WriteValue(InProperty->GetName(), PropertyValue); } } else if (const UBoolProperty* BoolProp = Cast<const UBoolProperty>(InProperty)) { const bool PropertyValue = BoolProp->GetPropertyValue(InPropertyData); JsonWriter->WriteValue(InProperty->GetName(), PropertyValue); } else if (const UArrayProperty* ArrayProp = Cast<const UArrayProperty>(InProperty)) { JsonWriter->WriteArrayStart(InProperty->GetName()); FScriptArrayHelper ArrayHelper(ArrayProp, InPropertyData); for (int32 ArrayEntryIndex = 0; ArrayEntryIndex < ArrayHelper.Num(); ++ArrayEntryIndex) { const void* ArrayEntryData = ArrayHelper.GetRawPtr(ArrayEntryIndex); WriteArrayEntry(ArrayProp->Inner, ArrayEntryData); } JsonWriter->WriteArrayEnd(); } else { const FString PropertyValue = DataTableUtils::GetPropertyValueAsString(InProperty, (uint8*)InRowData); JsonWriter->WriteValue(InProperty->GetName(), PropertyValue); } return true; }