Cannot convert JSON Object to class no matter what I try...always NULL

I am returning a perfect JSON Object from PHP MySQL(I tested on an online JSON converter, works fine, and it looks exactly like the example/stackoverflow examples).

I have tried using the JsonUtility.FromJson and FromJsonOverwrite methods and neither of them work…the object is always null when I check the properties.

I am at my wits end…this is simple stuff, it should not require 3+ hours and counting to deserialize a JSON object into a class.

www.text is returning:
{“id":“1”,“username”:“JimSmith”,“password”:“smith11”,“email”:"jimsmith@yahoo.com”,“isTrial”:“0”}

Test test = new test();
JsonUtility.FromJsonOverwrite(www.test, user); //Returing all NULL’s

Test test1 = JsonUtility.FromJson(www.text);:wink: //Returning all NULL’s

Here is the class object

[Serializable]
public class Test
{
public string id { get; set; }
public string username { get; set; }
public string password { get; set; }
public string email { get; set; }
public string isTrial { get; set; }
}

What is wrong? This is driving me crazy

Unity’s json doesn’t work with properties, but works with fields. At least, I never had it work with properties. Json.net works with properties. As per their docs Unity - Scripting API: JsonUtility.FromJsonOverwrite you’ll notice they use fields. Convert your properties to fields and it should work.

And use FromJson if it’s a new item, overwrite if you just need it to overwrite some values.

1 Like

If you want to use properties, just add a backing field and don’t serialize the properties themselves. Not sure exactly how to specify this using JsonUtility though as I use Json.NET myself