J'ai un json
comme celui-ci (retiré une partie de celui-ci car il est pas un problème)JsonSerializationException
{
"obj" : {
"id" : "a18",
"param" : {
"system" : 0,
"member_fill" : "0",
"name" : "MainAnketa",
"multi" : 0
}
}
}
J'essaie de le désérialiser avec l'aide de Newton.Json à l'objet suivant:
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;
}
}
}
Mais recevoir cette erreur:
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.
Quel peut être le problème avec le système attribut?
avez-vous essayé de changer public Liste FieldsOrder; pour string [] FieldsOrder? Whatr arrive? –