Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

C# Xml to Json

XDocument doc = XDocument.Load(@"c:	est.xml"); //or XDocument.Parse(xmlData)
            string jsonText = JsonConvert.SerializeXNode(doc);
            // dynamic dyn = JsonConvert.DeserializeObject<ExpandoObject>(jsonText);
            dynamic results = JsonConvert.DeserializeObject<dynamic>(jsonText);
            
            JArray items = (JArray)results["UserList"]["User"];
            int girilen = items.Count;
            
            
            foreach (dynamic item in results)
            {
                Console.WriteLine(item.UserList);
            }
Comment

c# xml to json

string xml = @"<?xml version='1.0' standalone='no'?>
/*<root>
  <person id='1'>
  <name>Alan</name>
  <url>http://www.google.com</url>
  </person>
  <person id='2'>
  <name>Louis</name>
  <url>http://www.yahoo.com</url>
  </person>
</root>
";
*/
XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);

string json = JsonConvert.SerializeXmlNode(doc);

Console.WriteLine(json);
// {
//   "?xml": {
//     "@version": "1.0",
//     "@standalone": "no"
//   },
//   "root": {
//     "person": [
//       {
//         "@id": "1",
//         "name": "Alan",
//         "url": "http://www.google.com"
//       },
//       {
//         "@id": "2",
//         "name": "Louis",
//         "url": "http://www.yahoo.com"
//       }
//     ]
//   }
// }
Comment

PREVIOUS NEXT
Code Example
Csharp :: c# handle dbnull value 
Csharp :: how to locate a specific element in a list c# 
Csharp :: how to make a string in c# 
Csharp :: entity framework insert 
Csharp :: dictionary string list int c# 
Csharp :: c# read all lines from filestream 
Csharp :: how to add to a list only items that are not already in the list c# 
Csharp :: cs string to enum 
Csharp :: Reverse Coding Challenge 1 
Csharp :: Kill System Process in C# 
Csharp :: unity add button 
Csharp :: unity convert number to notation 
Csharp :: c# api bypass ssl certificate 
Csharp :: how to send button name for method in c# 
Csharp :: primitive types c# 
Csharp :: c# how to call methods from another class 
Csharp :: c# remove all items from list where item value is null 
Csharp :: c# make file writable 
Csharp :: C# Switch and case 
Csharp :: how to turn on/off Particle System unity 
Csharp :: list sort c# 
Csharp :: get ad user using email address microsoft graph C# 
Csharp :: concatenation in c# 
Csharp :: c# get string in parentheses 
Csharp :: vb.net center form in screen 
Csharp :: Printing pattern in c# 
Csharp :: how to sign in with your unity id in unity hub 
Csharp :: get index brushes properties c# 
Csharp :: nunit cleanup after all tests 
Csharp :: c# custom event handler with parameters 
ADD CONTENT
Topic
Content
Source link
Name
6+8 =