return jsSerializer.Deserialize<MamDataResponseHolder>(stringJson);
抛出异常:
Type 'System.String' is not supported for deserialization of an array.
但我没有看到问题。
public class MamDataResponseHolder
{
public MamDataResponsePair[] configuration { get; set; }
public string Status { get; set; }
}
public class MamDataResponsePair
{
public string id { get; set; }
public MamDataResponsecriteria[] criterias { get; set; }
}
public class MamDataResponsecriteria
{
public Guid criteriaId { get; set; }
public string[] domains { get; set; }
public string domainsException { get; set; }
}
这是 json:
{
"configuration": [{
"id": "Coupon Body",
"criterias": [{
"criteriaId": "c7150fc2-72b9-4628-a199-dd5c0bdeef1b",
"domains": [""],
"domainsException": [""]
}]
}],
"Status": "succeeded"
}
最佳答案
您的模型和 Json 不匹配。看一下domainsException
。在你的 Json 中它显然是一个字符串数组,但在你的模型中它只是一个字符串。
除此之外:您确定要在 Json 中添加 [""]
吗?这样你就可以得到一个带有空字符串的数组,而不是一个空数组。
关于c# - JSON 反序列化为对象失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15356881/