I have the following JSON:
{"success":1,
"return":{
"funds": {
"usd":0,
"btc":0,
"ltc":0
},
"rights": {
"info":1,
"trade":0,
"withdraw":0
},
"transaction_count":1,
"open_orders":0,
"server_time":1406470221
}
}
I'm trying to deserialize it with:
JsonConvert.DeserializeObject<UserInfo>(jsonString);
Classes are as follows:
public class UserInfo
{
[JsonProperty("transaction_count")]
public int TransactionCount { get; set; }
[JsonProperty("open_orders")]
public int OpenOrders { get; set; }
[JsonProperty("server_time")]
public int ServerTime { get; set; }
[JsonProperty("funds")]
public Funds Funds { get; set; }
[JsonProperty("rights")]
public Rights Rights { get; set; }
}
public class Funds
{
[JsonProperty("btc")]
public decimal Btc { get; set; }
[JsonProperty("ltc")]
public decimal Ltc { get; set; }
[JsonProperty("usd")]
public decimal Usd { get; set; }
};
public class Rights
{
[JsonProperty("info")]
public bool Info { get; set; }
[JsonProperty("trade")]
public bool Trade { get; set; }
[JsonProperty("withdraw")]
public bool Withdraw { get; set; }
}
I tried not using the attributes and other tutorials, but nothing seems to work.. =(
Why doesn't it work? I don't know how to set return as a root, for example. Is it possible?
Thank you.
You don't need to create a wrapper/root class just for this, as others answers suggest.
You can parse the whole thing into a JObject
, and then convert just the return
node into a UserInfo
object.
JObject obj = JObject.Parse(jsonStr);
var userInfo = obj["return"].ToObject<UserInfo>();
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments