How can I use my own row struct to create my own datatable?

USTRUCT(BlueprintType)
struct FJsonData : public FTableRowBase
{
GENERATED_USTRUCT_BODY()
public:
FJsonData()
:pid(0)
{}
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = “JPhrase”)
int32 pid;
};

UCLASS(Blueprintable)
class BPATTEMPT_API UJson2DataTable : public UDataTable
{
GENERATED_UCLASS_BODY()

public:
UPROPERTY(EditAnywhere, Category = “My Object Properties”)
FJsonData fjsonData;
};

As you can see, I have my own structure, and I want to create my own datatable in C++ which will use FJsonData as it’s row structure. How can I set my own structure as DataTable’s row structure?
Anyone has Idea? I’ve searching google for several days, but there’s no answer.

What I’m trying to do is parsing Json data and create a datatable asset with it from C++ so that I can use it in Blueprint level.

What exactly do you want import json to asset or directly use json data in asset?

Never mind! I found the way to do that. Will upload how I did that to my website someday.
What I did is just implementing my own json parser so that it can add data to the datatable which is already allocated to the actor

Thanks!

I want to create a datatable from the data I parsed from Json. Which means, I want import Json in C++ level, and creates an asset.If there’s any way I can creates Datatable with the data I parsed from Json, that will do too. Actually, Unreal provides functionality to import Json with certain structure to creates datatable. But when I tried that, it didn’t work properly. Most of the values are wrongly parsed, If you know how to do that, please tell me. Thanks!

Hello,ArtainEx! Can share give your websitem,what your give may be is very useful to me,Thank you!

Did you read this?


Edit:

Here’s the creation of the datatable using custom struct.

Although, I’m using a C++ struct here, this method will work for blueprint structs as well.

USTRUCT(Blueprintable)
struct FExampleDatatableRow : public FTableRowBase
{
	GENERATED_BODY()

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
	FString SomeVar;
};

http://i.imgur.com/rMNwYzK.png/

http://i.imgur.com/3Zj5MWH.png

And to get data from such data table in C++:

UDataTable* DataTable; // populate it however you want
const FName RowName = FName("SomeRow");
FExampleDatatableRow* FoundRow = DataTable->FindRow<FExampleDatatableRow>(RowName, "");

Well, basically what I did is creating datatable in UE4 editor level, and allocate it to my actor. Then actor creates the datatable contents based on the structure I defined. What I referenced is Unreal’s Json parser itself. I’m in the middle of my semester, so detail explanation will be uploaded somewhere around December

Thanks for reply, and yes I did. But this is just a reference for how to use datatable which is already created, not creating new datatable.

Alright, i’ve edited my comment and changed it into an answer.
Hope this helps.

UE4.12 has some troubles with importing UDataTable from JSON. Try switching to 4.13 - all of my problems have gone after this switch.

Regarding Json import, I did the following.

  1. Locate row structure:

     UScriptStruct* ImportRowStruct = LoadObject<UScriptStruct>(nullptr, TEXT("/Game/Blueprints/RowStruct.RowStruct")); // I used script structure to allow data table to be used from blueprints without any C++ game code
    
  2. Create data table:

    UPackage* NewPackage = CreatePackage(nullptr, *PackagePath);
    NewPackage->FullyLoad();
    EObjectFlags Flags = RF_Public | RF_Standalone;
    UDataTable* NewTable = NewObject<UDataTable>(NewPackage, UDataTable::StaticClass(), TableName, Flags);
    NewTable->RowStruct = ImportRowStruct;
    
  3. Store Json to a file. Save Json file name inside new data table:

     NewTable->AssetImportData->Update(FullJsonFileName);
    
  4. Call re-import for this table, so all Json data will be imported into the data table

     FReimportHandler* ReimportFactory = NewObject<UReimportDataTableFactory>();
     check(ReimportFactory->Reimport(NewTable));
    

The code has some capabilities for updating existing table using reimport, which are not listed here. Using DataTableFactory simplifies workflow a lot. For instance, if you’ll update contents of the Json file, it will be automatically reimported into the engine (with a prompt to user).

Hope this helps.