MVC型号返回null
我的控制器中有一个JSON字符串。当我将其验证到我的模型中时,它正在返回一个空值。这里非常奇怪的是,这是在一段时间之前起作用的,然后停止了。关于这里有什么问题的想法?这是一个API电话,所以我也没有更改JSON的奢侈。 Tcustlst是从模型中返回零的问题孩子。
json(结果):
“ {\”响应\“:{\” cerrormessage \“:\” \“ \”,\“ MoreRecordSavailable \”:false,\ false,\ \“ tcustlst \”: :[{{{\“ custno \”:324161.0,\“ Shipto \”:\“ \”,\“ name \”:\“ test \ \/(nickname)\/(nickname)\”,\ \“ addr1 \” 111 \“,\” addr2 \“:\” \“,\” city \“:\” nyc \ \“,\” state \ \“:\” ny \“,\” zipcd \“:\” 555555-1234 \“,\” ordbal \“:0.0,\” totalbal \“:20451.67,\” sortfld \“:\” 123456 \“}}}}}}}}}}“
controller code> controller code:
CustomerList.Rootobject records = JsonConvert.DeserializeObject<CustomerList.Rootobject>(result);
return View(records);
modal code:modal code: model:model:model::
using Newtonsoft.Json;
using System.Collections.Generic;
namespace WebappsIntranet.Models
{
public class CustomerList
{
public class Rootobject
{
public string cErrorMessage { get; set; }
public bool moreRecordsAvailable { get; set; }
public tCustLst tCustList { get; set; }
}
public class tCustLst
{
[JsonProperty("t-custLst")]
public List<tCustcomerList> tcustomerlist { get; set; }
}
public class tCustcomerList {
public float custNo { get; set; }
public string shipTo { get; set; }
public string name { get; set; }
public string addr1 { get; set; }
public string addr2 { get; set; }
public string city { get; set; }
public string state { get; set; }
public string zipCd { get; set; }
public float ordBal { get; set; }
public float totalBal { get; set; }
public string sortFld { get; set; }
}
}
}
I have a json string in my controller. When i deserialize that into my model, it's returning a null value. The very strange part here is that this was working a while ago then stopped. Any thoughts as to what's wrong here? This is an api call, so i don't have the luxury of changing the json either. tCustLst is the problem child that is returning null from the model.
json (result):
"{\"response\":{\"cErrorMessage\":\"\",\"moreRecordsAvailable\":false,\"tCustLst\":{\"t-custLst\":[{\"custNo\":324161.0,\"shipTo\":\"\",\"name\":\"TEST \\/ (NICKNAME)\",\"addr1\":\"P.O. BOX 111\",\"addr2\":\"\",\"city\":\"NYC\",\"state\":\"NY\",\"zipCd\":\"55555-1234\",\"ordBal\":0.0,\"totalBal\":20451.67,\"sortFld\":\" 123456\"}]}}}"
controller code:
CustomerList.Rootobject records = JsonConvert.DeserializeObject<CustomerList.Rootobject>(result);
return View(records);
model:
using Newtonsoft.Json;
using System.Collections.Generic;
namespace WebappsIntranet.Models
{
public class CustomerList
{
public class Rootobject
{
public string cErrorMessage { get; set; }
public bool moreRecordsAvailable { get; set; }
public tCustLst tCustList { get; set; }
}
public class tCustLst
{
[JsonProperty("t-custLst")]
public List<tCustcomerList> tcustomerlist { get; set; }
}
public class tCustcomerList {
public float custNo { get; set; }
public string shipTo { get; set; }
public string name { get; set; }
public string addr1 { get; set; }
public string addr2 { get; set; }
public string city { get; set; }
public string state { get; set; }
public string zipCd { get; set; }
public float ordBal { get; set; }
public float totalBal { get; set; }
public string sortFld { get; set; }
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论