Download

How to use FJsonObjectConverter?

Hello, trying to grab data from configs, using JsonObjectStringToUStruct to parse the data, however it keeps saying unresolved externals?

I’ve already added JsonUtilities to my PublicDependencyModuleNames, and included “Runtime/JsonUtilities/Public/JsonObjectConverter.h” to the top of the code.

Struct to be parsed into:


 USTRUCT()
 struct FMode2DLayerRuntime
 {
     GENERATED_USTRUCT_BODY()

     FMode2DLayerRuntime() {}

     UPROPERTY() FString Name = "Default";
     UPROPERTY() float Depth = 0;
 };

Line of code (with test string) to parse:


 FString testStr = "(Name=\"Path Detail\",Depth=-150.000000)";
 FMode2DLayerRuntime layer;
 FJsonObjectConverter::JsonObjectStringToUStruct(testStr, &layer, 0, 0);

Other FJsonObjectConverter functions work just fine, so why does this one give unresolved externals? Am I using it wrong?
Thanks!

If you have “Json” + “JsonUtilities” + header it should work.
Try recreating the Intermediate folder.

You should have these module dependendencies: “Json”, “JsonUtilities”
And this include: “JsonObjectConverter.h”

Also, your example is not valid json, it should be surrounded by {} instead of (), the field names should be wrapped in quotes, and general convention is to start them with a lowercase character

Ah, I was missing the “Json” module, problem solved! Thanks guys!

Also, the example was just to show the forums for simplicity, the actual code pulls from the unreal configs, which happen to be setup that way :stuck_out_tongue:

The config is not in json format, so that is very questionable… I guess it might work in some cases