您好,欢迎来到[编程问答]网站首页   源码下载   电子书籍   软件下载   专题
当前位置:首页 >> 编程问答 >> .NET >> NewtonsoftJson反序列化,自定义类型获取到null

NewtonsoftJson反序列化,自定义类型获取到null

来源:网络整理     时间:2016/6/9 7:33:12     关键词:null,json

关于网友提出的“NewtonsoftJson反序列化,自定义类型获取到null”问题疑问,本网通过在网上对“NewtonsoftJson反序列化,自定义类型获取到null”有关的相关答案进行了整理,供用户进行参考,详细问题解答如下:

问题:NewtonsoftJson反序列化,自定义类型获取到null
描述:

struct

public struct MODEL
    {
        public USERMODEL userModel;
        public string code;
        public string msg;
        public string expMsg;
    }
 public struct USERMODEL
    {    
         public string USERNAME;
        public string ORGNAME;
        public string USERID;
    }
{"user":{"USERNAME":"超级管理员","ORGNAME":"中华人民共和国","USERID":1},"code":0,"msg":"操作成功","expMsg":""}
 MODEL model = (MODEL)Newtonsoft.Json.JsonConvert.DeserializeObject(jsonResult, typeof(MODEL));
            USERMODEL usermodel = model.userModel;
这个时候, 自定义类型 USERMODEL  ,获取到的都是null,查阅了一些文档,没有找到好的解决办法,求高手指教啊
解决方案1:

1、如楼上:用属性别 用字段
2、userModel改为user

解决方案2:

用属性,别用字段
private string username;
public string USERNAME
{
set {username = value;}
get{return username;}
}


以上介绍了“NewtonsoftJson反序列化,自定义类型获取到null”的问题解答,希望对有需要的网友有所帮助。
本文网址链接:http://www.codes51.com/itwd/1601265.html

相关图片

相关文章