Question from a developer:
I have a lot of little data items to store in user data, so I'd like to group things up so that they take fewer keys. Can you provide some example code showing how to do this?
Question from a developer:
I have a lot of little data items to store in user data, so I'd like to group things up so that they take fewer keys. Can you provide some example code showing how to do this?
Certainly! Here are two simple examples showing how to use JSON stringify and parse to quickly transform complex JSON objects to strings, which you can then use as the Value in a Key/Value pair, and then deseriallize it back to a JSON object.
Take a JSON object, turn it into a string, and write it to User Read Only Data (the Key is "EmbeddedJson" for both examples):
var jsonObject = { Name: "foo", Level: 3, Type: "thing", Stuff: [ 10, 12, 4, 2 ] };
var jsonString = JSON.stringify(jsonObject);
var response = server.UpdateUserReadOnlyData( { PlayFabId: currentPlayerId, Data: { EmbeddedJson: jsonString } } );
Read out an encoded string and turn it back into a JSON object:
var response = server.GetUserReadOnlyData( { PlayFabId: currentPlayerId, Keys: [ "EmbeddedJson" ] } );
var reconstructedJSON = JSON.parse( response.Data.EmbeddedJson.Value );
No one has followed this question yet.