Avatar of sudheer89
sudheer89

asked on 

Json to Xml conversion

Hi, i am tryong to convert json output to xml. can you please explain me how i can do that in c#? and also what namespaces do i have to use to access the functions regarding the serialization and deserialization of the json. please explain it with some example.

thank you
C#Web Languages and Standards.NET ProgrammingMicrosoft Development

Avatar of undefined
Last Comment
Bob Learned
ASKER CERTIFIED SOLUTION
Avatar of Ioannis Paraskevopoulos
Ioannis Paraskevopoulos
Flag of Greece image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of sudheer89
sudheer89

ASKER

i tried that above link but it is saying like jsonconvert was not there in the current context like that. is there any other way we can do that?
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Can you post a sample record in json and the output you desire.  I am not well versed in C# myself but converting from json to xml could be easy or complex depending on the data.  

If you start out with

{
     "person": {
      "id": "1",
      "name": "Alan",
      "role": "Admin1"
      }
}

is it ok to end up with

<person>
     <id>1</id>
     <name>Alan</name>
     <role>Admin1</role>
</person>

or do you need more detail in your xml?

I think if you can provide sample input and output, experts can help you code the conversion.
Avatar of aikimark
aikimark
Flag of United States of America image

@sudheer89

Is this a one-time conversion?

What have you found during your Internet/EE searches on the subject? There are a lot of hits when I did a search.  
Here is the most interesting/promising one:
http://blog.djekldevelopments.co.uk/?p=317 (conversion using Newtonsoft.Json namespace from http://james.newtonking.com/projects/json/help/)

Did anything you've tried come close to a solution?
Avatar of sudheer89
sudheer89

ASKER

the one you show me is correct, but when i am trying to convert that code in the c# its giving the namespace errors and other things. so you please post that conversion code for me and the namespaces, references that are added before using these things. and also one more question i am hp UFT tool to automate the services. when i try to convert the data from json to xml it is saying that the data at the root node is invalid. do have any idea what is that error was?


thank you
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

@sudheer89, do you want to open up this question or ask a new one?   I appreciate the points but did if did my answer give you what you needed?
Avatar of Bob Learned
Bob Learned
Flag of United States of America image

The first link from jyparask was a good one, and the code was clear, so if the NuGet package was installed, and the code was used, the only issue I could see is that your code was missing a using statement in order to reference JsonConvert.
.NET Programming
.NET Programming

The .NET Framework is not specific to any one programming language; rather, it includes a library of functions that allows developers to rapidly build applications. Several supported languages include C#, VB.NET, C++ or ASP.NET.

137K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo