小编dom*_*enu的帖子

如何干净地反序列化JSON,其中字符串值包装在同名对象中

我想将一些奇怪的JSON反序列化为C#类:

{
    "Result": {
        "Client": {
            "ProductList": {
                "Product": [
                    {
                        "Name": {
                            "Name": "Car polish"
                        }
                    }
                ]
            },
            "Name": {
                "Name": "Mr. Clouseau"
            },
            "AddressLine1": {
                "AddressLine1": "Hightstreet 13"
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

json2csharp为JSON生成以下类:

public class Name
{
    public string Name { get; set; }
}

public class Product
{
    public Name Name { get; set; }
}

public class ProductList
{
    public List<Product> Product { get; set; }
}

public class Name2
{
    public string Name …
Run Code Online (Sandbox Code Playgroud)

c# json json.net deserialization

6
推荐指数
1
解决办法
1660
查看次数

标签 统计

c# ×1

deserialization ×1

json ×1

json.net ×1