gpt4 book ai didi

c# - 通用名称的 JSON 数字根

转载 作者:行者123 更新时间:2023-11-30 21:59:23 24 4
gpt4 key购买 nike

我有一个如下所示的 JSON 文件。

{
"1000": {
"id": 1000,
"name": "Clothes, Shoes and Bags",
"path_from_root": [
{
"id": 1000,
"name": "Clothes, Shoes and Bags"
}
],
"children_categories": [
{
"id": 1001,
"name": "Accessories"
},
{
"id": 2422,
"name": "Athletic Shoes"
},
{
"id": 2303,
"name": "Baby Clothes"
},
{
"id": 2115,
"name": "Backpacks"
},
{
"id": 1071,
"name": "Bags"
},
{
"id": 2105,
"name": "Bags and Purses"
},
{
"id": 2087,
"name": "Children's Outfits"
},
{
"id": 2051,
"name": "Coats, Jackets and Vests"
},
{
"id": 3192,
"name": "Dresses and Skirts"
},
{
"id": 3336,
"name": "Glasses"
},
{
"id": 2249,
"name": "Others"
},
{
"id": 2092,
"name": "Overalls"
},
{
"id": 1366,
"name": "Pants, Shorts & Bermudas"
},
{
"id": 3191,
"name": "School Uniforms"
},
{
"id": 1894,
"name": "Shirts"
},
{
"id": 2353,
"name": "Shoes"
},
{
"id": 2417,
"name": "Suits"
},
{
"id": 2139,
"name": "Swimwear"
},
{
"id": 1979,
"name": "T-shirts and Blouses"
},
{
"id": 2254,
"name": "Underwear and Lingerie"
}
],
"attributes_required": false,
"max_pictures_per_item": 12,
"max_title_length": 60,
"max_price": null,
"min_price": null,
"listing_allowed": false
},
"1001": {
"id": 1001,
"name": "Accessories",
"path_from_root": [
{
"id": 1000,
"name": "Clothes, Shoes and Bags"
},
{
"id": 1001,
"name": "Accessories"
}
],
"children_categories": [
{
"id": 1055,
"name": "Boy"
},
{
"id": 1022,
"name": "For Men"
},
{
"id": 1002,
"name": "For Women"
},
{
"id": 1038,
"name": "Girl"
}
],
"attributes_required": false,
"max_pictures_per_item": 12,
"max_title_length": 60,
"max_price": null,
"min_price": null,
"listing_allowed": false
},
"1002": {
"id": 1002,
"name": "For Women",
"path_from_root": [
{
"id": 1000,
"name": "Clothes, Shoes and Bags"
},
{
"id": 1001,
"name": "Accessories"
},
{
"id": 1002,
"name": "For Women"
}
],
"children_categories": [
{
"id": 1011,
"name": "Beanies"
},
{
"id": 1008,
"name": "Belly Dance"
},
{
"id": 1007,
"name": "Belts"
},
{
"id": 1003,
"name": "Berets"
},
{
"id": 1004,
"name": "Caps"
},
{
"id": 1014,
"name": "Gloves"
},
{
"id": 1006,
"name": "Hats"
},
{
"id": 1013,
"name": "Neckerchiefs"
},
{
"id": 1015,
"name": "Others"
},
{
"id": 1016,
"name": "Pashmina Scarves"
},
{
"id": 1005,
"name": "Scarves"
},
{
"id": 1017,
"name": "Semi Precious Jewelry"
},
{
"id": 1009,
"name": "Shawls"
},
{
"id": 1020,
"name": "Ski Caps"
},
{
"id": 1010,
"name": "Stoles"
},
{
"id": 1018,
"name": "Suspenders"
},
{
"id": 1019,
"name": "Tiaras"
},
{
"id": 1012,
"name": "Ties"
},
{
"id": 1021,
"name": "Veils"
}
],
"attributes_required": false,
"max_pictures_per_item": 12,
"max_title_length": 60,
"max_price": null,
"min_price": null,
"listing_allowed": false
},
"1003": {
"id": 1003,
"name": "Berets",
"path_from_root": [
{
"id": 1000,
"name": "Clothes, Shoes and Bags"
},
{
"id": 1001,
"name": "Accessories"
},
{
"id": 1002,
"name": "For Women"
},
{
"id": 1003,
"name": "Berets"
}
],
"children_categories": [],
"attributes_required": false,
"max_pictures_per_item": 12,
"max_title_length": 60,
"max_price": null,
"min_price": null,
"listing_allowed": false
}
}

如果你看到,根名称就像

1000
1001
1002
1003

我想将它反序列化为一个对象。这些数字下面的结构是相同的。

有人可以建议我如何为此生成类吗?并使用 NewtonSoft 进行反序列化?

请注意,我无法更改 JSON,它的文件非常大(大约 16MB)。

最佳答案

有一个非常酷的功能叫做将 JSON 作为类粘贴:

enter image description here

参见 here .注意:这是 originally came with 的一项功能visual studio 扩展 web essentials。因此,根据您的 VS 版本,您可能需要 install this extension .


如果您粘贴第一个根节点,它会生成这些类:

public class Rootobject
{
public _1000 _1000 { get; set; }
}

public class _1000
{
public int id { get; set; }
public string name { get; set; }
public Path_From_Root[] path_from_root { get; set; }
public Children_Categories[] children_categories { get; set; }
public bool attributes_required { get; set; }
public int max_pictures_per_item { get; set; }
public int max_title_length { get; set; }
public object max_price { get; set; }
public object min_price { get; set; }
public bool listing_allowed { get; set; }
}

public class Path_From_Root
{
public int id { get; set; }
public string name { get; set; }
}

public class Children_Categories
{
public int id { get; set; }
public string name { get; set; }
}

这可能是您需要的。也许稍微改进一下。

关于c# - 通用名称的 JSON 数字根,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29301592/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com