I'm pulling Json data from my server and intending to read it into a profile.
The code runs right up to the userProfile1 = JsonUtility.FromJson<UserProfile>(www.text);
and stops. I tried putting a debug line before and after and the after debug never fires.
I think the issue perhaps has something to do with how Unity's JsonUtility expects the data format to be, but I'm not sure exactly what as I get no error back.
string baseurl = "http://55.55.55.55/api/";
public string loginId = "test@spam.com";
public UserProfile userProfile1;
void Start()
{
userProfile1 = new UserProfile();
StartCoroutine(GetUserProfile(loginId));
}
IEnumerator GetUserProfile(string email)
{
string url = baseurl + "users/email/" + email;
// Call server
WWW www = new WWW(url);
yield return www;
// Read returned user profile
if (www.error == null)
{
userProfile1 = JsonUtility.FromJson<UserProfile>(www.text);
}
else
{
Debug.Log("WWW Error: " + www.error);
}
}
Here's the class for the profile:
[System.Serializable]
public class UserProfile
{
public string _id;
public string first_name;
public string last_name;
public string email;
public string nick;
public string join_date;
public int age;
public string sex;
public int inventory_slot;
public int __v;
}
Here's the Json data from the server as grabbed by www.text
[
{
"_id":"58b92a058f9565e76d364437",
"first_name":"Test",
"last_name":"Name",
"email":"tinkle@spam.com",
"nick":"Tinkle",
"age":42,
"sex":"male",
"__v":0,
"inventory_slot":200000,
"join_date":"2017-02-26T00:36:10.266Z"
}
]