MVC型号返回null

发布于 2025-02-05 09:04:15 字数 2197 浏览 1 评论 0原文

我的控制器中有一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文