简体   繁体   English

c#json反序列化复杂对象

[英]c# json deserialization complex objects

I have a problem deserializing a json file, this is the json:我在反序列化 json 文件时遇到问题,这是 json:

[
    {
        "id": "id", 
        "number": "48", 
        "date": "17-01-2020",
        "details": [
            {
                "id": "id",
                "code": "code",
                "description": "desc"
            },
            {
                "id": "id",
                "code": "code",
                "description": "desc"

            }
        ],
        "address": "add",
        "note": null 
    },
    {
        "id": "id",
        "number": "55",
        "date": "17-01-2020",
        "details": [
            {
                "id": "id",
                "code": "code",
                "description": "desc"
            },
            {
                "id": "id",
                "code": "code",
                "description": "desc"
            }
        ],
        "address": "add",
        "note": null
    }
]

this is my code:这是我的代码:

 var result = httpClient.GetAsync(".....").Result;
 List<Docu> doc= new JavaScriptSerializer().Deserialize<List<Docu>>(result.Content.ReadAsStringAsync().Result);

class Docu contains definition of id, number, date, details and:类 Docu 包含 id、数字、日期、详细信息的定义以及:

public List<Details> det{ get; set; }

Class Details contains id, code and description definition类详细信息包含 id、代码和描述定义

I can deserialize everything except complex object details, it returns null from deserialization, how I can fix this?我可以反序列化除复杂对象细节之外的所有内容,它从反序列化中返回 null,我该如何解决这个问题? I need to fill the list of details我需要填写详细信息列表

You have wrong name for List<Details> property您的List<Details>属性名称有误

it should be它应该是

public List<Details> details{ get; set; }

according to json you have shown根据你所展示的json

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM