I'm getting User IDs (int64) from JSON and then passing them into a function to populate user data. However the JSON ID value I get changes once I pass it through a iEnumerator function. Any idea why this happens?
I have printed the values and know for sure they are the expected JSON values before i pass them.
I am getting the IDs with GetTeachersStudentList
and passing them into PopulateStudentGamesAndTutorial
. The dictionaries I am using to store the IDs and data are initialized right before GetTeachersStudentList
is called.
IEnumerator GetTeachersStudentList()
{
//get user information from server call
Dictionary<string, string> headers = new Dictionary<string,string>();
headers.Add("Access-Token", PlayerData.accessToken);
string url = studentURL += "?staffId=" + PlayerData.currentUser.staffId;
WWW www = new WWW(url, null, headers);
yield return www;
StudentListWebResponse = www.text;
PlayerData.studentList = StudentListWebResponse;
//parse json
JSONArray students = (JSONArray) JSON.Parse(StudentListWebResponse);
expectedStudentsToPopulate = students.Count;
//populate each users data
for (int i = 0; i < students.Count; i++)
{
string userInformation = students[i].ToString();
JSONObject studentJsonObject = (JSONObject) JSON.Parse(userInformation);
foreach (var item in studentJsonObject)
{
//look for id, then use that id to populate user data
if (item.Key == "id")
{
StartCoroutine(PopulateStudentGamesAndTutorial(item.Value));
}
}
}
PlayerData.control.Save();
}
IEnumerator PopulateStudentGamesAndTutorial(Int64 id)
{
//get games with id
Dictionary<string, string> headers = new Dictionary<string,string>();
headers.Add("Access-Token", PlayerData.accessToken);
string studentGameURL = serverManager.GamesURL(id);
WWW gamesWWW = new WWW(studentGameURL, null, headers);
yield return gamesWWW;
PlayerData.StudentListWithGames.Add(id, gamesWWW.text);
//get tutorials with id
string tutorialURL = serverManager.TutorialURL(id);
WWW wwwGetTutorialsCompleted = new WWW(tutorialURL, null, headers);
yield return wwwGetTutorialsCompleted;
JSONArray tutorialArray = (JSONArray) JSON.Parse(wwwGetTutorialsCompleted.text);
List<int> tutorialIDList = new List<int>();
for (int i = 0; i < tutorialArray.Count; i++)
{
tutorialIDList.Add(tutorialArray[i]["id"]);
}
PlayerData.StudentListWithTutorials.Add(id, tutorialIDList);
PlayerData.control.Save();