5

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
  • 1
    The second example is not valid JSON.
    – Thanatos
    Jun 3, 2010 at 0:38

1 Answer 1

4

Never mind, Just did it with:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.