.

Convert Json To Xml

code

var jsonOutput = @"{""Feeds"":[{""InstrumentName"":""Natural Gas"",""DailyHigh"":3.497,""DailyLow"":3.439,""Change"":0.15882183078255849,""InstrumentID"":123,""BuyRate"":3.471,""SellRate"":3.466},{""InstrumentName"":""Heating Oil"",""DailyHigh"":3.0944,""DailyLow"":3.0436,""Change"":0.70009768804949535,""InstrumentID"":430,""BuyRate"":3.0935,""SellRate"":3.0915}],""Type"":11}";
var myelement = JsonConvert.DeserializeXmlNode(jsonOutput, "ThisGetsIgnored").FirstChild; //Newtonsoft.Json.JsonConvert
var xml = myelement.InnerXml;
Console.WriteLine(xml);

input

{
   "Feeds":[
      {
         "InstrumentName":"Natural Gas",
         "DailyHigh":3.497,
         "DailyLow":3.439,
         "Change":0.15882183078255849,
         "InstrumentID":123,
         "BuyRate":3.471,
         "SellRate":3.466
      },
      {
         "InstrumentName":"Heating Oil",
         "DailyHigh":3.0944,
         "DailyLow":3.0436,
         "Change":0.70009768804949535,
         "InstrumentID":430,
         "BuyRate":3.0935,
         "SellRate":3.0915
      }
   ],
   "Type":11
}

output

<Feeds>
  <InstrumentName>Natural Gas</InstrumentName>
  <DailyHigh>3.497</DailyHigh>
  <DailyLow>3.439</DailyLow>
  <Change>0.15882183078255849</Change>
  <InstrumentID>123</InstrumentID>
  <BuyRate>3.471</BuyRate>
  <SellRate>3.466</SellRate>
</Feeds>
<Feeds>
  <InstrumentName>Heating Oil</InstrumentName>
  <DailyHigh>3.0944</DailyHigh>
  <DailyLow>3.0436</DailyLow>
  <Change>0.70009768804949535</Change>
  <InstrumentID>430</InstrumentID>
  <BuyRate>3.0935</BuyRate>
  <SellRate>3.0915</SellRate>
</Feeds>
<Type>11</Type>

What's your thoughts on this?

*

Protected by WP Anti Spam