Deserialize unnamed json array to object in c #

It's amazing how to deserialize the following line in C #:

"[{\"access_token\":\"thisistheaccesstoken\"}]"

I know how to do this if json was:

"{array=[{\"access_token\":\"thisistheaccesstoken\"}]}"

I would do it like this:

public class AccessToken
{
    public string access_token {get;set;}
    public DateTime expires { get; set; }
}

public class TokenReturn
{
    public List<AccessToken> tokens { get; set; }
}

JavaScriptSerializer ser = new JavaScriptSerializer();
TokenReturn result = ser.Deserialize<TokenReturn>(responseFromServer);

But without this array name, I'm not sure. Any suggestions?

Thank!

+5
source share
1 answer

Nothing, Just did it with:

        JavaScriptSerializer ser = new JavaScriptSerializer();
        List<AccessToken> result = ser.Deserialize<List<AccessToken>>(jsonString);
+4
source

All Articles