3
I have that code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Diagnostics;
using System.Xml;
using Newtonsoft.Json;
using System.Net;
using System.Xml.Linq;
using Newtonsoft.Json.Linq;
namespace PowderToyUpdater
{
static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
WebClient web = new WebClient();
var value = web.DownloadString("http://powdertoy.co.uk/Browse/Comments.json?ID=1681176&Start=0&Count=20");
XmlDocument xdoc = (XmlDocument)JsonConvert.DeserializeXmlNode(value);
XmlWriter w = XmlWriter.Create("comments_.xml");
xdoc.WriteTo(w);
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace PowderToyUpdater
{
public struct Comment
{
public string Username;
public string Userid;
//public string Gravatar;
public string CommentContent;
public string Timestamp;
public string FormattedUsername;
}
}
But when JSON is converted to XML and stored in a file, part of XML is missing.
<?xml version="1.0" encoding="utf-8"?><User><root><Username>Sandwichlizard</Username><UserID>105412</UserID><Gravatar>/Avatars/105412_40.png</Gravatar><Text>front page.</Text><Timestamp>1424281388</Timestamp><FormattedUsername>Sandwichlizard</FormattedUsername></root><root><Username>ndutoit</Username><UserID>133746</UserID><Gravatar>http://www.gravatar.com/avatar/88ff6ca3f7391896d88ea1f6ac46c3f8?s=40&amp;d=http%3A%2F%2Fpowdertoy.co.uk%2FDesign%2FImages%2FAvatar.png&amp;r=pg</Gravatar><Text>what is fp?</Text><Timestamp>1424279967</Timestamp><FormattedUsername>ndutoit</FormattedUsername></root><root><Username>Lord_Bowserinator</Username><UserID>130740</UserID><Gravatar>/Avatars/130740_40.png</Gravatar><Text>fp again</Text><Timestamp>1417569227</Timestamp><FormattedUsername>Lord_Bowserinator</FormattedUsername></root><root><Username>Sandwichlizard</Username><UserID>105412</UserID><Gravatar>/Avatars/105412_40.png</Gravatar><Text>sure. I will make a tutorial save. that will be easier than just talking about it here. I will leave a link in this save when it is ready. I will also publish it.</Text><Timestamp>1417561239</Timestamp><FormattedUsername>Sandwichlizard</FormattedUsername></root><root><Username>Anonymous100</Username><UserID>92366</UserID><Gravatar>/Avatars/92366_40.png</Gravatar><Text>Sandwich would you mind explaining to me the basic of all thesse fancy filt drives? I know that it has something to do with the fact that a color of filt when beamed at dtec with aray changes the filts color that is next to the dtec, but I dont understand how that info is decoded, and how it is written in the first place.</Text><Timestamp>1417541787</Timestamp><FormattedUsername>Anonymous100</FormattedUsername></root><root><Username>tombattraw</Username><UserID>85950</UserID><Gravatar>http://www.gravatar.com/avatar/a9a4ec31425b097ae496b8f027cdf016?s=40&amp;d=http%3A%2F%2Fpowdertoy.co.uk%2FDesign%2FImages%2FAvatar.png&amp;r=pg</Gravatar><Text>try recording a pong game</Text><Timestamp>1417535992</Timestamp><FormattedUsername>tombattraw</FormattedUsername></root><root><Username>Sandwichlizard</Username><UserID>105412</UserID><Gravatar>/Avatars/105412_40.png</Gravatar><Text>@mecha-man. sure. I have already started. I am working on a new printer save using this drive and I realized I needed some things and it forced me into a redesign. I will PM you.</Text><Timestamp>1417488946</Timestamp><FormattedUsername>Sandwichlizard</FormattedUsername></root><root><Username>mecha-man</Username><UserID>48475</UserID><Gravatar>/Avatars/48475_40.png</Gravatar><Text>@Sandwichlizard: Wanna work together to make it more compact?</Text><Timestamp>1417482098</Timestamp><FormattedUsername>mecha-man</FormattedUsername></root><root><Username>159819</Username><UserID>78051</UserID><Gravatar>/Avatars/78051_40.png</Gravatar><Text>is it posable to ither make a biger screen or smaler pixels?</Text><Timestamp>1417478468</Timestamp><FormattedUsername>159819</FormattedUsername></root><root><Username>0356459</Username><UserID>121388</UserID><Gravatar>http://www.gravatar.com/avatar/56261703f558a3503a1ab238fd4f4dac?s=40&amp;d=http%3A%2F%2Fpowdertoy.co.uk%2FDesign%2FImages%2FAvatar.png&amp;r=pg</Gravatar><Text>sorry man......but hey front page for a long time! :)</Text><Timestamp>1417412356</Timestamp><FormattedUsername>0356459</FormattedUsername></root><root><Username>Sandwichlizard</Username><UserID>105412</UserID><Gravatar>/Avatars/105412_40.png</Gravatar><Text>If someone would like to make a new video for this setup I would happily update the save with credit to the author of said video</Text><Timestamp>1417399984</Timestamp><FormattedUsername>Sandwichlizard</FormattedUsername></root><root><Username>Sandwichlizard</Username><UserID>105412</UserID><Gravatar>/Avatars/105412_40.png</Gravatar><Text>the crappy video is just to demo the drive. video made way better video's than mine for sure. thank you for your input.</Text><Timestamp>1417399892</Timestamp><FormattedUsername>Sandwichlizard</FormattedUsername></root><root><Username>0356459</Username><UserID>121388</UserID><Gravatar>http://www.gravatar.com/avatar/56261703f558a3503a1ab238fd4f4dac?s=40&amp;d=http%3A%2F%2Fpowdertoy.co.uk%2FDesign%2FImages%2FAvatar.png&amp;r=pg</Gravatar><Text>video did it better 2 times before. -1</Text><Timestamp>1417318433</Timestamp><FormattedUsername>0356459</FormattedUsername></root><root><Username>zsdrfty</Username><UserID>100327</UserID><Gravatar>/Avatars/100327_40.png</Gravatar><Text>Minecraft is more insane because it has analog computers. oog</Text><Timestamp>1417281395</Timestamp><FormattedUsername>zsdrfty</FormattedUsername></root><root><Username>Imperator</Username><UserID>123921</UserID><Gravatar>/Avatars/123921_40.png</Gravatar><Text>It's so cool that people can actually make a functioning computer within a game.</Text><Timestamp>1417269917</Timestamp><FormattedUsername>Imperator</FormattedUsername></root><root><Username>handicraftsman</Username><UserID>108835</UserID><Gravatar>/Avatars/108835_40.png</Gravatar><Text>Sandwichlizard, you can use my tablets without credits ) It's for you ) id:1677416</Text><Timestamp>1417268811</Timestamp><FormattedUsername>handicraftsman</FormattedUsername></root><root><Username>Ilog123</Username><UserID>104909</UserID><Gravatar>/Avatars/104909_40.png</Gravatar><Text>Try Making a Movie maker so you can copy/paste your film and check em out</Text><Timestamp>1417251254</Timestamp><FormattedUsername>Ilog123</FormattedUsername></root><root><Username>electronic_steve</Username><UserID>96362</UserID><Gravatar>/Avatars/96362_40.png</Gravatar><Text>id:1683229 108,3... i won!</Text><Timestamp>1417237206</Timestamp><FormattedUsername>electronic_steve</FormattedUsername></root><root><Username>zsdrfty</Username><UserID>100327</UserID><Gravatar>/Avatars/100327_40.png</Gravatar><Text>16.7k? We're over 1/10 of the capacity of a single-sided, single-density 5.25" floppy disk!</Text><Timestamp>1417229000</Timestamp><FormattedUsername>zsdrfty</FormattedUsername></root><root><Username>Fulchrum</Username><UserID>95857</UserID><Gravata <= Aqui falta o restante do xml.
And after converting JSON to XML, how do I use Xmltextreader or Xmlreader?
In the question title is to convert json to object, in the question body you are talking about a cut XML. Compose the question correctly.
– Ricardo
Why do you need data as XML? It would not be better to store it as JSON since it is being retrieved from the web service in this way?
– Zignd
Nathan, why didn’t my answer solve your problem? I tested what I said on it very well before posting here, and yet I’m with -1. That doesn’t seem fair at all.
– Zignd