开发者

Json Deserialize a List with in a List

Is it possible to deserialise a list with in a list using the JsonConvert.DeserializeObject?

Object: 
public class BusinessList
{
    public long Number{ get; set; }
    public string BusinessUnitCode { get; set; }
    public List<string> Codes { get; set; }
}

Json:

{"Number":111121,"BusinessUnitCode开发者_开发技巧":"ABC","Codes":["11111-2","14333-8"]}

Deserialization: 

var dataList = (List<BusinessList>)JsonConvert.DeserializeObject(reciveObject, typeof(List<BusinessList>), jsonSerializerSettings);

Error:

"Expected a JsonObjectContract or JsonDictionaryContract for 
type 'System.Collections.Generic.List`1
[PathResultsPortal.UI.Controllers.AnalyteDetails]', 
got 'Newtonsoft.Json.Serialization.JsonArrayContract'."

If you remove the Codes List from the BusinessList Object it works fine it can't seem to handle the list with in a list, is it even possible?


public class BusinessList 
{
    [JsonProperty(PropertyName = "Number")]
    public long Number{ get; set; }

    [JsonProperty(PropertyName = "BusinessUnitCode ")]
    public string BusinessUnitCode { get; set; }

    [JsonProperty(PropertyName = "Codes ")]
    public List<Codes> Codes { get; set; }
}

public class Codes
{
    public string Code { get; set; }
}

try this

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜