I'm a relatively new programmer and therefore have limited knowledge; however, I've been asked to create a program to convert loads of json files to xml files. There are a lot of them, and they're all different in terms of content (and i don't know exactly what's in them).
I've tried the following code
static void ProcessFiles(string path)
{
string[] files;
string[] directories;
XmlDocument xml = new XmlDocument();
files = Directory.GetFiles(path);
foreach (string file in files)
{
using (StreamReader r = new StreamReader(file))
{
string j = r.ReadToEnd();
string json = JsonConvert.DeserializeObject(j).ToString();
xml = JsonConvert.DeserializeXmlNode(json);
Console.Write(xml);
}
}
directories = Directory.GetDirectories(path);
foreach(string directory in directories)
{
ProcessFiles(directory);
}
}
I've managed to get this as my string 'json' and then get an error.
[
{
"Start": "date",
"Finish": "date",
"Subject": "",
"Comments": "",
"Site": "address",
"Location": null,
"Status": false,
"Arrived": true,
"Noshow": false,
"Services": "Initial Consultation",
"Attendees": [
{
"AccountId": 1111,
"AccountType": "MP",
"Name": "MMS (FP), Support "
},
{
"AccountId": 2220915,
"AccountType": "PA",
"Name": "Test, Patient "
}
]
},
]
I've been looking online for a solution but no luck so far. Can anyone help please?