Ich arbeite an Visual Studio
C#
Projekt und ich muss eine JSON
zu XML
konvertieren. Ich empfange die JSON
im String-Format. Das Problem ist, ich brauche einen Root-Knoten in der JSON
Struktur, wenn die JSON
hat keine, so dass ich in XML
mit gewünschten Format konvertieren kann.Wie füge ich einen Wurzelknoten zu einem JSON in C# mit Json.NET hinzu?
nehme an Ich habe diese JSON
:
{
"id": 1,
"name": {
"first": "Yong",
"last": "Mook Kim"
},
"contact": [{
"type": "phone/home",
"ref": "111-111-1234"
}, {
"type": "phone/work",
"ref": "222-222-2222"
}]
}
Und ich will Wurzelknoten zu diesem JSON
einfach so hinzuzufügen:
{
"user": {
"id": 1,
"name": {
"first": "Yong",
"last": "Mook Kim"
},
"contact": [{
"type": "phone/home",
"ref": "111-111-1234"
}, {
"type": "phone/work",
"ref": "222-222-2222"
}]
}
}
Wie kann ich es tun mit C#
und JSON.NET
?
Mögliches Duplikat [Json.NET serialisiert Objekt mit Root-Namen] (http:
Das resultierende JSON wie das aussieht // Stackoverflow .com/questions/16294963/json-net-serialize-objekt-mit-root-name) – Andrei