question

Philip Alexander Prates Machado avatar image
Philip Alexander Prates Machado asked

Parsing JSON responses in c++

I cant figure out how to handle json data in c++, in my case i am doing a get match and getting the response on the call back which returns a "FGetMatchResult" struct called "result".

In UE4 blueprints you would split the struct and get the members value and then drag from that and use a node called " Get Object Field", looking at this one would assume that something like the following would work:



result.Members[x].Attributes.GetObjectField(params);



Unfortunately this doesnt work and i cant find any documentation anywhere on how you are suposed to call this kind of stuff in c++, please let me know of any documentation that i missed or how this is done.

unreal
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
James Lennon avatar image
James Lennon answered

The way I have been doing it is with reading the plugin source code, reading the API reference for the call I want, and heavy usage of the auto complete (Visual Assist works but I use Rider for Unreal) to see what data is returned.

I haven't used FGetMatchResult in a project yet but typing it into a file gives me a few options:

  • Result.MatchId() is an FString
  • Result.Members is a TArray<FMatchmakingPlayerWithTeamAssignment>
  • Some other things as well, the source is here.

The reason you have to do it with a get fields is the C++ data types haven't been setup to be used with blueprint directly (in most cases it cannot be setup easily from what I can see). In C++ you don't have that restriction so you can work with the data types directly. There is an exception with JSON objects, those you still have to get/set field.

Edit:

Saw in the code you were trying to access Attributes which is a TSharedPtr so you would need to dereference it before accessing it. UE4 Docs on that.

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Philip Alexander Prates Machado avatar image Philip Alexander Prates Machado commented ·

I did not manage to dereference the variable, the methos "listChildren()" wasnt recognized by intelisense and did not compile BUT after using the arrow reference i managed to find "toJSONString()", i did try to use arrow reference before but intelisense didnt show anything for some reason.

At this point intelisense has made me lose more time than help.

0 Likes 0 ·
James Lennon avatar image James Lennon Philip Alexander Prates Machado commented ·

Default intellisense in Visual Studio is terrible with UE4, most people recommend VAX or Resharper if you are using Visual Studio. I use Rider for Unreal which has Resharper built into it (it's in free open beta for now).

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.