Deserialize unnamed json array into an object in c#
Posted
by rksprst
on Stack Overflow
See other posts from Stack Overflow
or by rksprst
Published on 2010-06-03T00:22:25Z
Indexed on
2010/06/03
0:34 UTC
Read the original article
Hit count: 373
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!
© Stack Overflow or respective owner