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