JsonSerializationException

时间:2013-05-27 07:45:19

标签: c# json.net json-deserialization

我有json这样的(删除部分内容,因为它不是问题)

   {
   "obj" : {
      "id" : "a18",
      "param" : {
         "system" : 0,
         "member_fill" : "0",
         "name" : "MainAnketa",
         "multi" : 0
      }
   }
}

我尝试在Newton.Json的帮助下将其反序列化为以下对象:

public class GetMainAnketaResponse
    {
        [JsonProperty(PropertyName = "obj")] public Anketa AnketaData;

        public class Anketa
        {
            [JsonProperty(PropertyName = "order")]
            public List<string> FieldsOrder;

            [JsonProperty(PropertyName = "id")]
            public string Id;

            [JsonProperty(PropertyName = "param")]
            public List<Parameter> Parameters;

            public class Parameter
            {
                [JsonProperty(PropertyName = "system")]
                public int System;

                [JsonProperty(PropertyName = "member_fill")]
                public string MemberFill;

                [JsonProperty(PropertyName = "name")]
                public string Name;

                [JsonProperty(PropertyName = "multi")]
                public int Multi;
            }
        }
    }

但收到此错误:

  

无法将当前JSON对象(例如{“name”:“value”})反序列化为类型'System.Collections.Generic.List`1 [SubscribeProLib.GetMainAnketaResponse + Anketa + Parameter]',因为该类型需要JSON数组(例如[1,2,3])正确反序列化。   要修复此错误,请将JSON更改为JSON数组(例如[1,2,3])或更改反序列化类型,使其成为普通的.NET类型(例如,不是像整数这样的基本类型,而不是类似的集合类型可以从JSON对象反序列化的数组或List。 JsonObjectAttribute也可以添加到类型中以强制它从JSON对象反序列化。   Path'obj.param.system',第61行,第20位。

System属性有什么问题?

1 个答案:

答案 0 :(得分:5)

您有List个参数,但您的JSON只有一个对象"param"

相关问题