0

我是 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。请帮助我。

谢谢

4

1 回答 1

1

使用此代码

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);
于 2013-09-13T12:17:32.320 回答