Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • API and SDK Questions /
avatar image
Question by Petter Vernersson · Oct 11, 2019 at 06:21 PM · apisunity3dsdks

What is the intended way to deserialize custom data from an api call.,Intended way to deserialize custom data from api call.

I am using the Unity SDK and have made an call to the api function "PlayFabMultiplayerAPI.CreateMatchmakingTicket"

The request accept custom data through "MatchmakingPlayerAttributes"

in this tutorial https://api.playfab.com/docs/tutorials/landing-tournaments/matchmaking-unity-quickstart

they have just entered the data like this.

...
		// Here we specify the creator's attributes.
		Attributes = new MatchmakingPlayerAttributes
		{
			DataObject = new
        		{
        			Skill = 24.4
        		},
		},
...

I have however made a class for my player attributes and entered the data like this.

PlayerAttributes myPlayerAttributes = new PlayerAttributes
{
	HostAdress = GetMyHostAdress()
};

...

                Attributes = new MatchmakingPlayerAttributes {
                    DataObject = myPlayerAttributes
                }
      
...

This is all fine from what I can see. But what is the intended way to get the data back again when retrieving it from another api call.

For example when using this api call.

PlayFabMultiplayerAPI.GetMatch(
	new GetMatchRequest 
	{
            MatchId = matchId,
            QueueName = "queuetest",
            ReturnMemberAttributes = true
        },

The tutorial never shows this.

I can get the DataObject and convert it back to my PlayerAttribute class structure by doing ToString on the DataObject and deserelize it from json to my PlayerAttribute class, but it feels like that isn't the intended way since the DataObject already is a PlayFab.Json.JsonObject.

How is it intended to convert "PlayFab.Json.JsonObject" to your own types?

,

I am using the Unity SDK and have made an call to the api function "PlayFabMultiplayerAPI.CreateMatchmakingTicket"
The request accept custom data through "MatchmakingPlayerAttributes"

in this tutorial https://api.playfab.com/docs/tutorials/landing-tournaments/matchmaking-unity-quickstart

they have just entered the data like this.

...
		// Here we specify the creator's attributes.
		Attributes = new MatchmakingPlayerAttributes
		{
			DataObject = new
        		{
        			Skill = 24.4
        		},
		},
...

I have however made a class for my player attributes and entered the data like this.

PlayerAttributes myPlayerAttributes = new PlayerAttributes
{
	HostAdress = GetMyHostAdress()
};

...

                Attributes = new MatchmakingPlayerAttributes {
                    DataObject = myPlayerAttributes
                }
      
...

This is all fine from what I can see. But what is the intended way to get the data back again when retrieving it from another api call.

For example when using this api call.

PlayFabMultiplayerAPI.GetMatch(
	new GetMatchRequest 
	{
            MatchId = matchId,
            QueueName = "queuetest",
            ReturnMemberAttributes = true
        },

The tutorial never shows this.

I can get the DataObject and convert it back to my PlayerAttribute class structure by doing ToString on the DataObject and deserelize it from json to my PlayerAttribute class, but it feels like that isn't the intended way since the DataObject already is a PlayFab.Json.JsonObject.

How is it intended to convert "PlayFab.Json.JsonObject" to your own types?

Comment

People who like this

0 Show 1
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Petter Vernersson · Oct 10, 2019 at 01:18 PM 0
Share

For some reason the post content and title got duplicated. And I don't seem to be able to edit it.

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Sarah Zhang · Oct 14, 2019 at 10:52 AM

There is no built-in SDK to convert this DataObject to the custom type object. We should deserialize it to JSON string then convert it to the custom type object. A possible workaround is to use Newtonsoft.Json to convert it. You can refer to the following code. You can download the unity package on the Github page. It may be similar to your original way. In a word, converting DataObject to JSONString is needed.

//AttributesDataModel.cs
public class AttributesDataModel
{
//should be correspond to your JSON path, in your code, your path is HostAdress, it should be HostAdress too
public string HostAddress { get; set; }
}
//use this function to convert Json to custom type
using Newtonsoft.Json;
…
var itemAttribute = JsonConvert.DeserializeObject<AttributesDataModel>(member.Attributes.DataObject.ToString());
Debug.Log("itemAttribute.HostAddress----->" + itemAttribute.HostAddress);
…
Comment

People who like this

0 Show 2 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Petter Vernersson · Oct 17, 2019 at 08:14 AM 1
Share

Ye, your suggestion is how I currently do it except I use the Json converter available in the playfab unity sdk.

And yes DataObject is by its definition of type object. But that is not was it is constructed as. If you use GetType on DataObject when retrieved from the api call you see that it is a PlayFab.Json.JsonObject.

I just thought it was weird that there had been an effort to construct a PlayFab.Json.JsonObject when I can't use that object to serialize it to my own type and instead has to do a third conversion to string first.

I did however found this forum post now.

https://community.playfab.com/questions/4521/executecloudscript-functionresult-frustration.html

Which explains the concerns I had.

avatar image Sarah Zhang Petter Vernersson · Oct 17, 2019 at 09:06 AM 0
Share

Yeah, it looks like I missed something thank you for sharing it.

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    2 People are following this question.

    avatar image avatar image

    Related Questions

    Any difference between Playfab C# SDK and PlayFab Unity SDK? 2 Answers

    How do POST from php to playfab,How can i do POST from php to playfab 1 Answer

    Unity Mirror and Playfab GameServers 1 Answer

    Saving long text data in one UpdatePlayerData call? 2 Answers

    How to download content from cdn? 1 Answer

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges