gpt4 book ai didi

c# - 序列化为 XML 时如何处理 JSON 键中的空格?

转载 作者:太空宇宙 更新时间:2023-11-03 11:00:36 26 4
gpt4 key购买 nike

我在 .NET 4.0 应用程序中使用 Json.NET,以便将 JSON RESTful 响应转换为 XML。如果 JSON 子键有空格,我在将 JSON 转换为 XML 时遇到问题。

到目前为止,我能够转换大多数 JSON 响应。

Here are example responses along with the code which I am using to generate the XML.

{
num_reviews: "2",
page_id: "17816",
merchant_id: 7165
}

这是导致错误的响应:

    [
{
headline: "ant bully",
created_date: "2010/06/12",
merchant_group_id: 10126,
profile_id: 0,
provider_id: 10000,
locale: "en_US",
helpful_score: 1314,
locale_id: 1,
variant: "",
bottomline: "Yes",
name: "Jessie",
page_id: "17816",
review_tags: [
{
Pros: [
"Easy to Learn",
"Engaging Story Line",
"Graphics",
"Good Audio",
"Multiplayer",
"Gameplay"
]
},
{
Describe Yourself: [
"Casual Gamer"
]
},
{
Best Uses: [
"Multiple Players"
]
},
{
Primary use: [
"Personal"
]
}
],
rating: 4,
merchant_id: 7165,
reviewer_type: "Verified Reviewer",
comments: "fun to play"
},
{
headline: "Ok game, but great price!",
created_date: "2010/02/28",
merchant_group_id: 10126,
profile_id: 0,
provider_id: 10000,
locale: "en_US",
helpful_score: 1918,
locale_id: 1,
variant: "",
bottomline: "Yes",
name: "Alleycatsandconmen",
page_id: "17816",
review_tags: [
{
Pros: [
"Easy to Learn",
"Engaging Story Line"
]
},
{
Describe Yourself: [
"Frequent Player"
]
},
{
Primary use: [
"Personal"
]
},
{
Best Uses: [
"Kids"
]
}
],
rating: 3,
merchant_id: 7165,
reviewer_type: "Verified Reviewer",
comments: "This is a cute game for the kids and at a great price. Just don't expect a whole lot."
}
]

到目前为止,我一直在考虑创建 JSON 数据到 C# 对象的映射并为该类生成 XML。但是,有没有办法保持这种动态?或者有没有办法将空格视为 %20 编码?

最佳答案

这个问题与how to validate JSON string before converting to XML in C#相同

如果您有任何疑问,请告诉我。

关于c# - 序列化为 XML 时如何处理 JSON 键中的空格?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17813635/

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