question

faisal3413 avatar image
faisal3413 asked

,KeyNotFoundException: The given key was not present in the dictionary.

,

Hi All,

I was testing unicorn battle project to understand the workflow of GetTitleData. I was successfully receiving all of the data in json format except the one which I added as "QuizData", this key is also in json and I am sure about that . Please see the following code and help me or give me some other sample code.

******************************************************************

public static Dictionary<string, Data> LevelData = new Dictionary<string, Data>();

public static void GetTitleData()

{ GetTitleDataRequest request = new GetTitleDataRequest() {

Keys = new List<string>() { "Classes", "Spells", "StartingCharacterSlots", "MinimumInterstitialWait", "CharacterLevelRamp", "Levels", "Achievements", "Sales", "Events", "Offers", "CommunityWebsite", "StandardStores","QuizData"}

};

DialogCanvasController.RequestLoadingPrompt(PlayFabAPIMethods.GetTitleData); PlayFabClientAPI.GetTitleData(request, OnGetTitleDataSuccess, PF_Bridge.PlayFabErrorCallback); }

public static void OnGetTitleDataSuccess(GetTitleDataResult result) {

Debug.Log("length "+result.Data.Count); // return 12, it should return 13

if(result.Data.ContainsKey("Classes"))

{ Spells = PlayFab.SimpleJson.DeserializeObject<Dictionary<string, UB_SpellDetail>>(result.Data["Spells"]); } if (result.Data.ContainsKey("QuizData")) { LevelData= PlayFab.SimpleJson.DeserializeObject<Dictionary<string, Data>>(result.Data["QuizData"]); Debug.Log("LevelDataCount " + LevelData.Count); }

}

********************************************************************

[System.Serializable] public class Data

{ int level { get; set; } int firstOperand { get; set; } int secondOperand { get; set; } string operation { get; set; }

Data() {}

Data(Data d) { if (d != null) { level = d.level; firstOperand = d.firstOperand; secondOperand = d.secondOperand; operation = d.operation;

}

}

}

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

·
brendan avatar image
brendan answered

Is this for Title ID CA30? When I make that same query against that Title ID, I'm getting all of the Keys requested back, including QuizData. Can you try making this query in Postman, to see if you get the same results?

2 comments
10 |1200

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

faisal3413 avatar image faisal3413 commented ·

Hi,

Thanks for you kind feedback.

Yes you are right with Title ID. Can you please send me the example script which you are using to make query in postman?

Regards,

Faisal

0 Likes 0 ·
brendan avatar image brendan faisal3413 commented ·

Sure - I was using the Server API call, since I didn't want to confuse things by creating a bogus player in your title:

POST /Server/GetTitleData HTTP/1.1
Host: CA30.playfabapi.com
Content-Type: application/json
X-SecretKey: {removed}
{
  "Keys": [ "Classes", "Spells", "StartingCharacterSlots", "MinimumInterstitialWait", "CharacterLevelRamp", "Levels", "Achievements", "Sales", "Events", "Offers", "CommunityWebsite", "StandardStores","QuizData" ]
}

You can also get our full Postman Collection here: https://api.playfab.com/sdks/postman

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.