Suraj
Suraj

Reputation: 433

Convert xml document to json

My code is as follows.

using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("TestStore1.xml", FileMode.Open, isoStore))
{
    using (StreamReader reader = new StreamReader(isoStream))
    {
        str = reader.ReadToEnd();
        XmlDocument doc = new XmlDocument();
        doc.LoadXml(str);
        string json = JsonConvert.SerializeXmlNode(doc);
    }
}

It is giving the error at the line of string json = JsonConvert.SerializeXmlNode(doc);

Error - Newtonsoft.Json.JsonConvert' does not contain a definition for 'SerializeXmlNode'

Upvotes: 2

Views: 1054

Answers (1)

TomDane
TomDane

Reputation: 1076

If you are using dotnet core, install the Newtonsoft.Json package via nuget.

Upvotes: 1

Related Questions