question

westenmasterson avatar image
westenmasterson asked

UE4 Blueprints Retrieving JSON Arrays from Player Data

I'm having some issues with Playfab in UE4 when using blueprints. Specifically I am having issues with retrieving values that have been stored in Playfab as JSON Arrays. I have some data that I want to store on Playfab for players to know what levels they have completed, what levels are ongoing, and what levels they have yet to play. I've been able to store the data onto Playfab correctly, but now the issue is being able to read that data back. There will potentially be hundreds of levels for this game so I want to just store everything as one long JSON Array under a key of "Levels". I've been able to retrieve and decode a singular "Level" that I have for testing to make sure I can retrieve the data, but I am having issues trying to figure out how to get that out as an array.

As you can see from my test, I retrieve the JSON value as a string, turn it into a JSON object and then I can grab the data I need (When trying to grab the value as a JSON object it was not working). But I don't know how to go about doing this for my array. I have tried several setups and tried to use the "As Array" node after retrieving the JSON object form the value and several other ways but it always comes back with data that does not work or I can not traverse.

Here is my playfab data, and the current setup. I can get "Level" to print out the fields, but I can never pull anything from "Levels"

unreal
json-array-1.png (478.7 KiB)
json-array-3.png (20.6 KiB)
10 |1200

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

westenmasterson avatar image
westenmasterson answered

To anyone who has a similar problem, here is the code I ended up using to retrieve the JSON via blueprints. I ended up having to change the stored data to include an extra Value that I could pull as an Array.


arraysolution.png (258.4 KiB)
10 |1200

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

Made Wang avatar image
Made Wang answered

In my test, the error occurred in the Decode Json method. What is required here is a string in JsonObject format, and the data you store in PlayFab is a string in JsonArray format. You can try outputting the whole value after the As String method.

Regarding how to handle String and JSON data in blueprints, I am not an expert in this area, and I recommend seeking professional support from the Unreal forums.

10 |1200

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

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.