I have problem with deserialize json object. I read many threads on stackoverflow but I didn't find solution. I use .net 2.0 and Newtonsoft library.
Below is json string:
{
"data": {
"custom_fields": [{
"field": "segmentid",
"value": "B"
},
{
"field": "subsegmentid",
"value": "TM3"
},
{
"field": "contactpersonid",
"value": "000187_003"
},
{
"field": "firstname",
"value": "ZBIGNIEW"
},
{
"field": "agreetment",
"value": "1"
},
{
"field": "contactname",
"value": "ZBIGNIEW TESTOWY"
},
{
"field": "decisionmaking",
"value": "0"
},
{
"field": "lastpurchase",
"value": ""
},
{
"field": "agethresholds",
"value": "0"
},
{
"field": "tendercust",
"value": ""
}],
"email": "[email protected]",
"state": "1"
},
"status": "OK"
}
I developed two classes but I still get below error.
Cannot deserialize the current JSON object (e.g. {\"name\":\"value\"}) into type 'System.Collections.Generic.List`1[FMIntegration.DataFM]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly.\r\nTo 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.\r\nPath 'data.email'
var SubscriberGet = JsonConvert.DeserializeObject<SubscriberGet>(json);
public class SubscriberGet
{
[JsonProperty("status")]
public string Status { get; set; }
[JsonProperty("data")]
public List<DataFM> Data { get; set; }
}
public class DataFM
{
[JsonProperty("email")]
public string Email { get; set; }
[JsonProperty("custom_fields")]
public List<String> custom_fields { get; set; }
[JsonProperty("state")]
public string State { get; set; }
}