question

Kim Strasser avatar image
Kim Strasser asked

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"?

Title Data
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

·
Seth Du avatar image
Seth Du answered

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.

1 comment
10 |1200

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

Kim Strasser avatar image Kim Strasser commented ·

Thanx. It works 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.