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 Kim Strasser · Jan 26 at 04:30 PM · Title Data

How can I get TitleData json value in the client?

I get an error message when I want to get the json value of my TitleData key/value pair.

Error CS1061: 'string' does not contain a definition for 'Value' and no accessible extension method 'Value' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)
bool active = false;
DateTime nextreset;

var result = await PlayFabClientAPI.GetTitleDataAsync(new PlayFab.ClientModels.GetTitleDataRequest());
string key = "Leaderboard-1-1";
if (result.Result.Data.ContainsKey(key))
{
    if ((result.Result.Data[key].Value != null) && (result.Result.Data[key].Value != string.Empty))
    {
        Dictionary<string, object> dic = PlayFabSimpleJson.DeserializeObject<Dictionary<string, object>>(result.Result.Data[key].Value.ToString());
        if (dic.TryGetValue("Active", out object a))
        {
            active = Convert.ToBoolean(a);
        }
        if (dic.TryGetValue("NextReset", out object b))
        {
            nextreset = Convert.ToDateTime(b);
        }
    }
}

What is wrong with my code? How can I get the values of "Active" and "NextReset"?

bildschirmfoto-2021-01-26-um-171253.png (112.7 kB)
Comment

People who like this

0 Show 0
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

1 Reply

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by SethDu · Jan 27 at 07:11 AM

The format is incorrect.

From the screenshot, “Leaderboard-1-1” is an object with <string,string> values, you cannot deserialize it to <string, object>. The following codes should work.

PlayFabClientAPI.GetTitleData(
    new GetTitleDataRequest { },
    result=> {
        string key = "Leaderboard-1-1";
        var data = PlayFab.PluginManager.GetPlugin<ISerializerPlugin>(PluginContract.PlayFab_Serializer).DeserializeObject<Dictionary<string,string>>(result.Data[key]);
        print(data["Active"]);
        print(data["NextReset"]);
    },
Fail=> { });

BTW, PlayFabSimpleJson should have been deprecated in the latest SDK, please try to avoid using it.

Comment

People who like this

0 Show 1 · 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 Kim Strasser · Jan 27 at 05:09 PM 0
Share

Thanx. It works now.

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

    3 People are following this question.

    avatar image avatar image avatar image

    Related Questions

    Use Shared Group Data for a live event system? 4 Answers

    Timed quest and semi online machmaking 3 Answers

    Limits - Data Value Updates Per 15 Secs, 5 Mins and 1 Hr 1 Answer

    Using Entities for non-player data? 1 Answer

    KeyNotFoundException: The given key was not present in the dictionary. 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