Null class when deserializing Json C#

I have this PHP

            if ($result->num_rows === 1) {
                    $sql = ("SELECT username, email, plan, activationdate, terminationdate FROM users WHERE username = '$username' LIMIT 1");
$res = mysqli_query($conn,$sql);
if ($res->num_rows === 1) {
while($row = mysqli_fetch_object($res)){
$arr = array( $row);
echo json_encode($arr);

which returns this json correctly [{"username":"xxxxx","email":"xxxxxx","plan":"0","activationdate":"","terminationdate":""}]

Now in c# i tried to deserialize using List<Information> resinfo = JsonConvert.DeserializeObject<List<Information>>(str2); and returns null value

Note that in the pic Null result but the json string is retunrning value as intended Json string

And this is my class

public class Information
{

    public static string username { get; set; }
    public static string email { get; set; }
    public static string plan { get; set; }
    public static string activationdate { get; set; }
    public static string terminationdate { get; set; }
}

Why am I getting null when I try to deserialize into the class and how can I deserialize correctly?

Its worth mentioning that I tried this var json = JsonConvert.DeserializeObject<List<Information>>(str2); with the same result

Upvotes: 0

Views: 61

Answers (1)

puko
puko

Reputation: 2970

It is because all your properties in your Information class are static. Remove static keyword and try it again.

JsonConvert.DeserializeObject will set only instance properties so they cannot be declared as static.

After execution take a look at removedFines variable (as in your image).

Upvotes: 3

Related Questions