在C#中反序列化json时出错

时间:2015-08-22 07:01:49

标签: c# json

这是我的Get Set Method Class

public class RechargeGridDTO
{

    public String from { get; set; }
    public String to { get; set; }
    public String errormsg { get; set; }
    public String status { get; set; }
    public RechargeInnerMsgGridInfo message { get; set; }
    public String type { get; set; }
    public String reqid { get; set; }
}
public class RechargeInnerMsgGridInfo
{
    public String mob {get;set;}
    public String rctype { get; set; }
    public String rcservice { get; set; }
    public String rcmobile { get; set; }
    public String rcamt { get; set; }
    public String rcpin { get; set; }
    public String mytxid { get; set; }
    public String optxid { get; set; }
    public String txid { get; set; }
    public String rcstatus { get; set; }
    public String rcmsg { get; set; }
    public String rctime { get; set; }
    public String rcbal { get; set; }
    public String rcsimbal { get; set; }
    public String rcremark { get; set; }
    public String rcchnnl { get; set; }
}

这是我想解析i-e的json响应:

msg = {
     "from":"nishantuser",
     "to":"smpp",
     "errormsg":null,
     "status":"s",
     "message":
        {
           "mob":"9999999999",
           "rctype":"Rr",
           "rcservice":"Aircel",
           "rcmobile":"8460149820",
           "rcamt":"20",
           "rcpin":"1234",
           "mytxid":"4850",
           "optxid":GUJNishant123,
           "txid":null,
           "rcstatus":s,
           "rcmsg":null,
           "rctime":null,
           "rcbal":null,
           "rcsimbal":null,
           "rcremark":null,
           "rcchnnl":null
       },
     "type":"RECHARGE",
     "reqid":"4850"
   }

当我解析这个json Response然后得到错误......

var ResponseData = JsonConvert.DeserializeObject<RechargeGridDTO>(msg);

请给我解决方案如何在C#中使用JsonConvert解析这种类型的响应

1 个答案:

答案 0 :(得分:2)

"optxid":GUJNishant123,

"rcstatus":s,

这些部分无效JSON。字符串需要引用:

"optxid":"GUJNishant123",

"rcstatus":"s",