【发布时间】:2017-11-02 20:02:51
【问题描述】:
我使用 newtonsoft 将对象序列化为 JSON。这是一个记录:
"Properties": {
"ProductId": "e2cba925-0720-465a-8c84-79626e9869e5",
"LinkName": "link",
"Brand": "brandx",
"SiteActive": true,
"RetailActive": true,
"BaseColor": null,
"BaseTextColor": null,
"BackGroundImageId": null,
"ProductGroupId": null,
"MadeInUSAID": null
},
"Display": {
"ProductId": "e2cba925-0720-465a-8c84-79626e9869e5",
"ShowWeb": false,
"ShowMobile": true,
"ShowDatavault": true,
"ShowDataVaultForPartners": true,
"ShowNewsroom": false
},
"Image": {
"ImageId": "e11ef84d-3c96-4fd9-a765-1f37e38ebc1a",
"ImageThumbnailId": "dfd87a61-9d59-4a46-8895-541a21e73b39",
"MD5": "3DECCFAA34946E1542BCCAD4DAC42CEC",
"SHA": null,
"SHA2_256": null,
"SHA2_512": null,
"DocumentType": null,
"ContentType": "image/jpeg",
"MaxWidth": null,
"MaxHeight": null,
"MaxResolution": null,
"FileExtension": null,
"FileName": "60144-1"
},
"ProductId": "e2cba925-0720-465a-8c84-79626e9869e5",
"SKU": "60144",
"ReceiptName": "blah blah blah",
"UPC": "081483803371",
"Taxable": true,
"ColorId": "46a809ab-ac78-44f2-bd62-303345e9ff32",
"ProductType": 1,
"PackQty": 1
},
{
"Description": {
"ProductDescriptionId": "1b1d812b-0568-41a6-a0ed-4488c32b66e0",
"ProductId": "2dc47c3e-7780-4768-bbae-6a1d6c4067ce",
"LanguageId": 57,
"Name": "widget 1",
"TitleTag": "widget 1",
"SEOText": null,
"Description": null,
"MetaDescription": null,
"InternalKeywords": null
}
我只需要从 JSON 中挑选某些字段并将这些值放入 XML 文档中。环顾四周,我看到很多将整个 JSON 转换为 XML 的示例,但我只需要特定的标签。有这样做的例子吗?
谢谢。
【问题讨论】:
-
你试过探索这个库吗:nuget.org/packages/Moonmile.ExDoc.Json
-
如果你只需要特定的值,难道你不能从你的 JSON 中获取它们,创建相应的对象来表示它们,然后对该对象进行 XML 化吗?
-
我可以使用我需要的值创建一个对象,我只需要知道如何将 JSON 中的值提取到我的对象中。 JSON用于多个项目,我只需要一个子集。例如,我需要名称、品牌。 SKU、UPC、描述......以及其他一些。我正在尝试获取这些物品。