I know there are a lot of questions regarding JSON spread all over the internet and here on StackOverflow. But I can't get my JSON to work as it should, so I hope I can get some help around here. [Working in C#, Visual Studio]
I've got the following code:
public void CheckRFID(string RFIDtag) {
[...SOME WORKING CODE]
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
System.Diagnostics.Debug.WriteLine(new StreamReader(response.GetResponseStream()).ReadToEnd());
currentuser = Newtonsoft.Json.JsonConvert.DeserializeObject<User[]>(new StreamReader(response.GetResponseStream()).ReadToEnd());
System.Diagnostics.Debug.WriteLine(currentuser[0].UserID);
}
This code keeps giving me "A first chance exception of type 'System.NullReferenceException' occurred in Database.dll. Additional information: Object reference not set to an instance of an object.".
As you can see I'm writing the response to debug log to see if I get a JSON, the result of this debug is [{"ID":"2","username":"IJK","gender":"F","color":"yellow"}]. Looks like a proper JSON line to me.
So, I'm stuck. I have no idea where to look, what I've done wrong...
And just for more info, this is the User.cs class:
public class User {
public int UserID { get; set; }
public string username { get; set; }
public string gender { get; set; }
public string color { get; set; }
}