【发布时间】:2016-06-02 16:02:14
【问题描述】:
我正在处理Visual StudioC# 项目,我需要将JSON 转换为XML。
我收到了字符串格式的JSON。
问题是,如果JSON 没有根节点,我需要在JSON 结构中有一个根节点,以便我可以转换为所需格式的XML。
假设我有这个JSON:
{
"id": 1,
"name": {
"first": "Yong",
"last": "Mook Kim"
},
"contact": [{
"type": "phone/home",
"ref": "111-111-1234"
}, {
"type": "phone/work",
"ref": "222-222-2222"
}]
}
我想像这样将根节点添加到JSON:
{
"user": {
"id": 1,
"name": {
"first": "Yong",
"last": "Mook Kim"
},
"contact": [{
"type": "phone/home",
"ref": "111-111-1234"
}, {
"type": "phone/work",
"ref": "222-222-2222"
}]
}
}
如何使用C# 和JSON.NET 做到这一点?
【问题讨论】: