我是json.net的新手。我的Json看起来如下。我需要访问json中的状态。请告诉我如何获取它。
{
"msg_id": "8923-15323-1332c61-1674bfd2872-5232e550-49204213240",
"sendondate": "2013-09-13 15:43:00",
"seq_id": {
"1": {
"valid": "true",
"credit": "1.00",
"linecount": 1,
"billcredit": 1,
"id_provider": "2",
"providerkey": "AT",
"regionKey": "AP",
"mnpID": "52",
"dlr_seq": 1,
"status": "DELIVER",
"remarks": ""
}
}
}
代码:
var data = JsonConvert.DeserializeObject<T>(datastring);
当我使用它时,我收到错误消息意外令牌:StartObject。请帮助我。
由于
答案 0 :(得分:2)
使用此代码
public class Response
{
[JsonProperty("msg_id")]
public string MsgId { get; set; }
[JsonProperty("sendondate")]
public string Sendondate { get; set; }
[JsonProperty("seq_id")]
public SeqId SeqId { get; set; }
}
public class SeqId
{
[JsonProperty("1")]
public Class1 value { get; set; }
}
public class Class1
{
[JsonProperty("valid")]
public string Valid { get; set; }
[JsonProperty("credit")]
public string Credit { get; set; }
[JsonProperty("linecount")]
public int Linecount { get; set; }
[JsonProperty("billcredit")]
public int Billcredit { get; set; }
[JsonProperty("id_provider")]
public string IdProvider { get; set; }
[JsonProperty("providerkey")]
public string Providerkey { get; set; }
[JsonProperty("regionKey")]
public string RegionKey { get; set; }
[JsonProperty("mnpID")]
public string MnpID { get; set; }
[JsonProperty("dlr_seq")]
public int DlrSeq { get; set; }
[JsonProperty("status")]
public string Status { get; set; }
[JsonProperty("remarks")]
public string Remarks { get; set; }
}
然后写
var obj = JsonConvert.DeserializeObject<Response>(Your_String);