views:

219

answers:

1

Wondering how to deserialize the following string in c#:

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

I know how to do it if the json was:

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

I'd 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 that array name, I'm not sure. Any suggestions?

Thanks!

+1  A: 

Never mind, Just did it with:

        JavaScriptSerializer ser = new JavaScriptSerializer();
        List<AccessToken> result = ser.Deserialize<List<AccessToken>>(jsonString);
rksprst