I am deserializing an Json string to Object.This is my Json string need to Deserialized.
{
"response": {
"total_results": 33,
"trades": [
{
"tid": "E231958349",
"num": 1,
"num_iid": 3424234,
"price": 200.07
}]
}
}
I have defined a response model.This is my code:
public class ResponseModel
{
public int total_results { set; get; }
public List<TradeModel> trades{ set; get;}
}
And I also have defined trades model:
public class TradeModel
{
#region Attribute
#region oid
private int tid;
public int Oid
{
get { return tid; }
set { tid = value; }
}
#endregion
#endregion
}
And this is my deserialize code:
public static ResponseModel MapResonseJsonToModel(string json)
{
ResponseModel orderModel = new ResponseModel();
orderModel = JsonConvert.DeserializeObject<ResponseModel>(json);
return orderModel;
}
My question is:Why everytime the total_results return 0,and the trades return null?The correct is 33,and not null trade object!
JsonConvert will be looking for a property named response
in ResponseModel
due to the format of your JSON. Try changing your JSON to only be the value of response, or create another class like this:
public class ResponseContainer
{
public ResponseModel response {get;set;}
}
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다