Let's talk JSON

I know I’m doing a whole lot wrong here, to be honest all documentation on JSON with UE4 is pretty vague.
Can anyone point me in the proper direction on how to plug JSON into C++ and read it properly as well as modify?


TSharedPtr<FJsonObject> JsonObject = MakeShareable(new FJsonObject());
TSharedRef< TJsonReader<> > JsonReader = TJsonReaderFactory<>::Create("{ table: { columnNames:  actor, height ], ColumnTypes:  String, float ], columnUnits:  null, m ], rows:   11111, 2.5 ],  11111, 2.4 ] ] } }");

    // Deserialize the JSON data

    if (FJsonSerializer::Deserialize(JsonReader, JsonObject) &&
        JsonObject.IsValid())
    {

        TSharedPtr<FJsonObject> jsonObj = JsonObject->GetObjectField("table");
        TArray<TSharedPtr<FJsonValue>> objArray = jsonObj->GetArrayField("rows");

        for (int32 i = 0; i < objArray.Num(); i++)
        {

            TArray<TSharedPtr<FJsonValue>> height = objArray*->AsArray();
            FString name = height[2]->AsString();

            UE_LOG(LogTemp, Warning, TEXT("Value I'm looking for %s"), *name);

        }
    }

Been referencing

http://www.wraiyth.com/?p=222
https://forums.unrealengine.com/deve…to-handle-json
https://forums.unrealengine.com/deve…lex-structures

To no avail
will continue endlessly troubleshooting, creating this post for some additional knowledge
What would be the best way to read JSON from a text file string?

I know the string I plugged into “JsonReader” is terribly wrong, that’s essentially where I gave up and started asking for help.

1 Like

Hi NachoBiznezz

I was expecting a weird question again, but is not the case, actually there is not documentation at all, I think because this class is simple and self explanatory, speaking about JSON everything is reduced to getArrayFields iterate through and get again until you find what you want, it is how it works, JSON are bound to what you are receiving / sending in a HTTP GET/POST, and how your application will work, In my case I just make a wrapper to make all available in blueprints, using functions similar to AsyncTaskDownloadImage.cpp

Also I saw people trying to use JSON as config files, if that is your intention, you can use the real system with configs file “.ini” ; here is the documentation just in case: Configuration Files | Unreal Engine Documentation

Best

What I’m doing isn’t self explanatory so I suppose I’ll just await a constructive response instead of repetitive useless criticism from someone who only half-reads posts and then replies for rep. :cool:

I’m looking for help and examples based on what I provided, not what you’re thinking, but thanks anyways.
You’re legit the prime example of someone who COULD help but NEVER does by resorting to sarcasm.

1 Like

Hi NachoBiznezz

I am sorry if I offended you somehow, it wasn’t my intention, I would like share some stuff I made related to JSON, this is my own plugin for Rest API: https://github.com/zkarmakun/JRestAPI
I would like share the whole project but I can’t because some access keys, the project itself is about Language learning, so for this I am receiving translation from this page: Translate API — Yandex Technologies, actually you can register for free and test jsons

Check my image, it is what I told your that your json parser is just bind to your app, in my case I made the GetRequest node and then Yandex page is asking me for the key, and some other PHP parameters, then if success I received all the info in a json UObject I made and I process the very specific json content coming from Yandex.

This is my opinion again, but UE json parser is very simple, basically holds all the functionally itself, Inside my github I have some other usage and how I made the UObject parser for blueprints, you can also read some other free resources like the VaRestAPI from other user here in the UE forum, also take a look to what I suggest before

Last comment if you allow me, nobody does hand holding, because is a bad practice, usually the people here show the path using examples from the engine source, that is what I did, but if somehow I offended you, once again!, it wasn’t my intention. if you have questions about the code, I will try to answer the best I can

Much more informative response, appreciate that but what I’m trying to do specifically is read JSON from a cached .TXT and if possible update it as well.

In C++ not blueprint.

To make your json string valid, just remove all spaces, put quotes around all string values, and escape all the quotation marks.
Also take a second look at


FString name = height[2]->AsString(); 

After you fix those two things, it should work fine.

Adjusted code to


TSharedPtr<FJsonObject> JsonObject = MakeShareable(new FJsonObject());
    TSharedRef< TJsonReader<> > JsonReader = TJsonReaderFactory<>::Create("{\"table\":{\"columnNames\":\"actor\",\"height\"],\"columnTypes\":\"String\",\"float\"],\"columnUnits\":[null,\"m\"],\"rows\":\"11111\",2.5],\"11111\",2.4]]}}");
    //{ table: { columnNames:  actor, height ], ColumnTypes:  String, float ], columnUnits:  null, m ], rows:   11111, 2.5 ],  11111, 2.4 ] ] } }");

    // Deserialize the JSON data

    if (FJsonSerializer::Deserialize(JsonReader, JsonObject) &&
        JsonObject.IsValid())
    {

        TSharedPtr<FJsonObject> jsonObj = JsonObject->GetObjectField("table");
        TArray<TSharedPtr<FJsonValue>> objArray = jsonObj->GetArrayField("rows");

        for (int32 i = 0; i < objArray.Num(); i++)
        {

            TArray<TSharedPtr<FJsonValue>> height = objArray*->AsArray();
            FString name = height[0]->AsString();

        UE_LOG(LogTemp, Warning, TEXT("Value I'm looking for %s"), *name);

        };
    };

Still resolving in the massive error below


2>SMyCompoundWidget.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class FString __cdecl FJsonValue::AsString(void)const " (__imp_?AsString@FJsonValue@@QEBA?AVFString@@XZ) referenced in function "public: void __cdecl SMyCompoundWidget::Construct(struct SMyCompoundWidget::FArguments const &)" (?Construct@SMyCompoundWidget@@QEAAXAEBUFArguments@1@@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class TArray<class TSharedPtr<class FJsonValue,0>,class FDefaultAllocator> const & __cdecl FJsonValue::AsArray(void)const " (__imp_?AsArray@FJsonValue@@QEBAAEBV?$TArray@V?$TSharedPtr@VFJsonValue@@$0A@@@VFDefaultAllocator@@@@XZ) referenced in function "public: void __cdecl SMyCompoundWidget::Construct(struct SMyCompoundWidget::FArguments const &)" (?Construct@SMyCompoundWidget@@QEAAXAEBUFArguments@1@@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl FJsonValueString::FJsonValueString(class FString const &)" (__imp_??0FJsonValueString@@QEAA@AEBVFString@@@Z) referenced in function "private: static bool __cdecl FJsonSerializer::Deserialize<wchar_t>(class TSharedRef<class TJsonReader<wchar_t>,0> const &,struct FJsonSerializer::StackState &)" (??$Deserialize@_W@FJsonSerializer@@CA_NAEBV?$TSharedRef@V?$TJsonReader@_W@@$0A@@@AEAUStackState@0@@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl FJsonValueString::~FJsonValueString(void)" (__imp_??1FJsonValueString@@UEAA@XZ) referenced in function "public: virtual void * __cdecl FJsonValueString::`scalar deleting destructor'(unsigned int)" (??_GFJsonValueString@@UEAAPEAXI@Z)
2&gt;SMyCompoundWidget.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl FJsonValueNumber::FJsonValueNumber(double)" (__imp_??0FJsonValueNumber@@QEAA@N@Z) referenced in function "private: static bool __cdecl FJsonSerializer::Deserialize&lt;wchar_t&gt;(class TSharedRef&lt;class TJsonReader&lt;wchar_t&gt;,0&gt; const &,struct FJsonSerializer::StackState &)" (??$Deserialize@_W@FJsonSerializer@@CA_NAEBV?$TSharedRef@V?$TJsonReader@_W@@$0A@@@AEAUStackState@0@@Z)
2&gt;SMyCompoundWidget.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl FJsonValueNumber::~FJsonValueNumber(void)" (__imp_??1FJsonValueNumber@@UEAA@XZ) referenced in function "public: virtual void * __cdecl FJsonValueNumber::`scalar deleting destructor'(unsigned int)" (??_GFJsonValueNumber@@UEAAPEAXI@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl FJsonValueBoolean::FJsonValueBoolean(bool)" (__imp_??0FJsonValueBoolean@@QEAA@_N@Z) referenced in function "private: static bool __cdecl FJsonSerializer::Deserialize<wchar_t>(class TSharedRef<class TJsonReader<wchar_t>,0> const &,struct FJsonSerializer::StackState &)" (??$Deserialize@_W@FJsonSerializer@@CA_NAEBV?$TSharedRef@V?$TJsonReader@_W@@$0A@@@AEAUStackState@0@@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl FJsonValueBoolean::~FJsonValueBoolean(void)" (__imp_??1FJsonValueBoolean@@UEAA@XZ) referenced in function "public: virtual void * __cdecl FJsonValueBoolean::`scalar deleting destructor'(unsigned int)" (??_GFJsonValueBoolean@@UEAAPEAXI@Z)
2&gt;SMyCompoundWidget.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl FJsonValueArray::FJsonValueArray(class TArray&lt;class TSharedPtr&lt;class FJsonValue,0&gt;,class FDefaultAllocator&gt; const &)" (__imp_??0FJsonValueArray@@QEAA@AEBV?$TArray@V?$TSharedPtr@VFJsonValue@@$0A@@@VFDefaultAllocator@@@@@Z) referenced in function "private: static bool __cdecl FJsonSerializer::Deserialize&lt;wchar_t&gt;(class TSharedRef&lt;class TJsonReader&lt;wchar_t&gt;,0&gt; const &,struct FJsonSerializer::StackState &)" (??$Deserialize@_W@FJsonSerializer@@CA_NAEBV?$TSharedRef@V?$TJsonReader@_W@@$0A@@@AEAUStackState@0@@Z)
2&gt;SMyCompoundWidget.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl FJsonValueArray::~FJsonValueArray(void)" (__imp_??1FJsonValueArray@@UEAA@XZ) referenced in function "public: virtual void * __cdecl FJsonValueArray::`scalar deleting destructor'(unsigned int)" (??_GFJsonValueArray@@UEAAPEAXI@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl FJsonValueObject::FJsonValueObject(class TSharedPtr<class FJsonObject,0>)" (__imp_??0FJsonValueObject@@QEAA@V?$TSharedPtr@VFJsonObject@@$0A@@@@Z) referenced in function "private: static bool __cdecl FJsonSerializer::Deserialize<wchar_t>(class TSharedRef<class TJsonReader<wchar_t>,0> const &,struct FJsonSerializer::StackState &)" (??$Deserialize@_W@FJsonSerializer@@CA_NAEBV?$TSharedRef@V?$TJsonReader@_W@@$0A@@@AEAUStackState@0@@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl FJsonValueObject::~FJsonValueObject(void)" (__imp_??1FJsonValueObject@@UEAA@XZ) referenced in function "public: virtual void * __cdecl FJsonValueObject::`scalar deleting destructor'(unsigned int)" (??_GFJsonValueObject@@UEAAPEAXI@Z)
2&gt;SMyCompoundWidget.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl FJsonValueNull::FJsonValueNull(void)" (__imp_??0FJsonValueNull@@QEAA@XZ) referenced in function "private: static bool __cdecl FJsonSerializer::Deserialize&lt;wchar_t&gt;(class TSharedRef&lt;class TJsonReader&lt;wchar_t&gt;,0&gt; const &,struct FJsonSerializer::StackState &)" (??$Deserialize@_W@FJsonSerializer@@CA_NAEBV?$TSharedRef@V?$TJsonReader@_W@@$0A@@@AEAUStackState@0@@Z)
2&gt;SMyCompoundWidget.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: virtual __cdecl FJsonValueNull::~FJsonValueNull(void)" (__imp_??1FJsonValueNull@@UEAA@XZ) referenced in function "public: virtual void * __cdecl FJsonValueNull::`scalar deleting destructor'(unsigned int)" (??_GFJsonValueNull@@UEAAPEAXI@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: void __cdecl FJsonObject::SetField(class FString const &,class TSharedPtr<class FJsonValue,0> const &)" (__imp_?SetField@FJsonObject@@QEAAXAEBVFString@@AEBV?$TSharedPtr@VFJsonValue@@$0A@@@@Z) referenced in function "private: static bool __cdecl FJsonSerializer::Deserialize<wchar_t>(class TSharedRef<class TJsonReader<wchar_t>,0> const &,struct FJsonSerializer::StackState &)" (??$Deserialize@_W@FJsonSerializer@@CA_NAEBV?$TSharedRef@V?$TJsonReader@_W@@$0A@@@AEAUStackState@0@@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class TArray<class TSharedPtr<class FJsonValue,0>,class FDefaultAllocator> const & __cdecl FJsonObject::GetArrayField(class FString const &)const " (__imp_?GetArrayField@FJsonObject@@QEBAAEBV?$TArray@V?$TSharedPtr@VFJsonValue@@$0A@@@VFDefaultAllocator@@@@AEBVFString@@@Z) referenced in function "public: void __cdecl SMyCompoundWidget::Construct(struct SMyCompoundWidget::FArguments const &)" (?Construct@SMyCompoundWidget@@QEAAXAEBUFArguments@1@@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: class TSharedPtr<class FJsonObject,0> const & __cdecl FJsonObject::GetObjectField(class FString const &)const " (__imp_?GetObjectField@FJsonObject@@QEBAAEBV?$TSharedPtr@VFJsonObject@@$0A@@@AEBVFString@@@Z) referenced in function "public: void __cdecl SMyCompoundWidget::Construct(struct SMyCompoundWidget::FArguments const &)" (?Construct@SMyCompoundWidget@@QEAAXAEBUFArguments@1@@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl FJsonObject::FJsonObject(void)" (__imp_??0FJsonObject@@QEAA@XZ) referenced in function "private: static bool __cdecl FJsonSerializer::Deserialize<wchar_t>(class TSharedRef<class TJsonReader<wchar_t>,0> const &,struct FJsonSerializer::StackState &)" (??$Deserialize@_W@FJsonSerializer@@CA_NAEBV?$TSharedRef@V?$TJsonReader@_W@@$0A@@@AEAUStackState@0@@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2019: unresolved external symbol "__declspec(dllimport) public: __cdecl FJsonObject::~FJsonObject(void)" (__imp_??1FJsonObject@@QEAA@XZ) referenced in function "public: virtual void __cdecl SharedPointerInternals::TReferenceControllerWithDeleter<class FJsonObject,struct SharedPointerInternals::DefaultDeleter<class FJsonObject> >::DestroyObject(void)" (?DestroyObject@?$TReferenceControllerWithDeleter@VFJsonObject@@U?$DefaultDeleter@VFJsonObject@@@SharedPointerInternals@@@SharedPointerInternals@@UEAAXXZ)
2>SMyCompoundWidget.cpp.obj : error LNK2001: unresolved external symbol "public: virtual class TSharedPtr<class FJsonObject,0> const & __cdecl FJsonValue::AsObject(void)const " (?AsObject@FJsonValue@@UEBAAEBV?$TSharedPtr@VFJsonObject@@$0A@@@XZ)
2>SMyCompoundWidget.cpp.obj : error LNK2001: unresolved external symbol "protected: virtual class FString __cdecl FJsonValueArray::GetType(void)const " (?GetType@FJsonValueArray@@MEBA?AVFString@@XZ)
2>SMyCompoundWidget.cpp.obj : error LNK2001: unresolved external symbol "protected: virtual class FString __cdecl FJsonValueBoolean::GetType(void)const " (?GetType@FJsonValueBoolean@@MEBA?AVFString@@XZ)
2>SMyCompoundWidget.cpp.obj : error LNK2001: unresolved external symbol "protected: virtual class FString __cdecl FJsonValueNull::GetType(void)const " (?GetType@FJsonValueNull@@MEBA?AVFString@@XZ)
2>SMyCompoundWidget.cpp.obj : error LNK2001: unresolved external symbol "protected: virtual class FString __cdecl FJsonValueNumber::GetType(void)const " (?GetType@FJsonValueNumber@@MEBA?AVFString@@XZ)
2>SMyCompoundWidget.cpp.obj : error LNK2001: unresolved external symbol "protected: virtual class FString __cdecl FJsonValueObject::GetType(void)const " (?GetType@FJsonValueObject@@MEBA?AVFString@@XZ)
2>SMyCompoundWidget.cpp.obj : error LNK2001: unresolved external symbol "protected: virtual class FString __cdecl FJsonValueString::GetType(void)const " (?GetType@FJsonValueString@@MEBA?AVFString@@XZ)
2>SMyCompoundWidget.cpp.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl FJsonValue::TryGetArray(class TArray<class TSharedPtr<class FJsonValue,0>,class FDefaultAllocator> const * &)const " (?TryGetArray@FJsonValue@@UEBA_NAEAPEBV?$TArray@V?$TSharedPtr@VFJsonValue@@$0A@@@VFDefaultAllocator@@@@@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl FJsonValueArray::TryGetArray(class TArray<class TSharedPtr<class FJsonValue,0>,class FDefaultAllocator> const * &)const " (?TryGetArray@FJsonValueArray@@UEBA_NAEAPEBV?$TArray@V?$TSharedPtr@VFJsonValue@@$0A@@@VFDefaultAllocator@@@@@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl FJsonValue::TryGetBool(bool &)const " (?TryGetBool@FJsonValue@@UEBA_NAEA_N@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl FJsonValueBoolean::TryGetBool(bool &)const " (?TryGetBool@FJsonValueBoolean@@UEBA_NAEA_N@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl FJsonValueNumber::TryGetBool(bool &)const " (?TryGetBool@FJsonValueNumber@@UEBA_NAEA_N@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl FJsonValueString::TryGetBool(bool &)const " (?TryGetBool@FJsonValueString@@UEBA_NAEA_N@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl FJsonValue::TryGetNumber(double &)const " (?TryGetNumber@FJsonValue@@UEBA_NAEAN@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl FJsonValueBoolean::TryGetNumber(double &)const " (?TryGetNumber@FJsonValueBoolean@@UEBA_NAEAN@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl FJsonValueNumber::TryGetNumber(double &)const " (?TryGetNumber@FJsonValueNumber@@UEBA_NAEAN@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl FJsonValueString::TryGetNumber(double &)const " (?TryGetNumber@FJsonValueString@@UEBA_NAEAN@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl FJsonValue::TryGetObject(class TSharedPtr<class FJsonObject,0> const * &)const " (?TryGetObject@FJsonValue@@UEBA_NAEAPEBV?$TSharedPtr@VFJsonObject@@$0A@@@@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl FJsonValueObject::TryGetObject(class TSharedPtr<class FJsonObject,0> const * &)const " (?TryGetObject@FJsonValueObject@@UEBA_NAEAPEBV?$TSharedPtr@VFJsonObject@@$0A@@@@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl FJsonValue::TryGetString(class FString &)const " (?TryGetString@FJsonValue@@UEBA_NAEAVFString@@@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl FJsonValueBoolean::TryGetString(class FString &)const " (?TryGetString@FJsonValueBoolean@@UEBA_NAEAVFString@@@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl FJsonValueNumber::TryGetString(class FString &)const " (?TryGetString@FJsonValueNumber@@UEBA_NAEAVFString@@@Z)
2>SMyCompoundWidget.cpp.obj : error LNK2001: unresolved external symbol "public: virtual bool __cdecl FJsonValueString::TryGetString(class FString &)const " (?TryGetString@FJsonValueString@@UEBA_NAEAVFString@@@Z)



did you add “Json” to PublicDependencyModuleNames in your build.cs file?

:mad::mad::mad::mad::mad::mad::mad::mad::mad::mad:

1 Like

Here’s a blog I wrote about it.

1 Like