Question

I have a json like this (removed a part of it as it's not a problem)

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

I try to deserialize it with the help of Newton.Json to the following object:

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;
            }
        }
    }

But receive this error:

Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.List`1[SubscribeProLib.GetMainAnketaResponse+Anketa+Parameter]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object. Path 'obj.param.system', line 61, position 20.

What can be the problem with the System attribute?

Was it helpful?

Solution

You have a List of parameters, but your JSON only has a single object as "param".

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top