TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
Ankit Saraogi
NA
10
11.2k
How do I populate XML (converted from JSON) to data grid vie
Feb 18 2018 11:47 AM
My main objective is to convert a json file to CSV format with some formatting.
For that I have converted the json to xml.
Now, I want to populate the nested XML to a datagridview and then further process some formatting commands.
The issue is that one parent table and child table of the converted XML file are having the same name 'item'.
Please help me resolve the issue. The primary goal is to convert the file as is done by the website https://json-csv.com
I do not prefer using any third party reference. Please let me know if it can done using System.Runtime.Serialization.Json
The error received by me is
The table (item) cannot be the child table to itself in nested relations.
My code:
using
System;
using
System.Collections.Generic;
using
System.ComponentModel;
using
System.Data;
using
System.Drawing;
using
System.Linq;
using
System.Text;
using
System.Windows.Forms;
using
System.Runtime.Serialization;
using
System.Xml;
using
System.Xml.Linq;
using
System.ServiceModel.Web;
using
System.Runtime.Serialization.Json;
using
System.Xml.XPath;
namespace
JsonToCsv
{
public
partial
class
Form1 : Form
{
public
Form1()
{
InitializeComponent();
}
private
void
button1_Click(
object
sender, EventArgs e)
{
string
Text = System.IO.File.ReadAllText(@
"C:\0.json"
);
var jsonReader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(Text),
new
System.Xml.XmlDictionaryReaderQuotas());
var root = XElement.Load(jsonReader);
DataSet ds =
new
DataSet();
System.IO.StringReader Reader =
new
System.IO.StringReader(root.ToString());
richTextBox1.Text = root.ToString();
ds.ReadXml(Reader);
DataTable dt =
new
DataTable();
ds.Tables.Add(dt);
dataGridView1.DataSource = dt;
} } }
The JSON file, the XML generated by the program and the output required are attached
Attachment:
Code.rar
Reply
Answers (
2
)
Connect to a specific IP address using Wamp Server
Multi Threading in Asp.Net 4.5