after one day trying to do what I was searching for finally I finished and thanks to "KORNfel Eliyahu peter"
here is the solution :
FISRT:
if I have a json string and I want to read it :
my string:
string json = "{\"employees\": [{ \"firstName\":\"John\" , \"lastName\":\"Doe\" },{ \"firstName\":\"Anna\" , \"lastName\":\"Smith\" }]}";
I do parsing using json.net library
JObject o = JObject.Parse(json);
here if print it
Console.WriteLine(o["employees"]);
SECOND:
Converting from json string to XML:
MY JSON STRING :
string 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'
} ]
}}";
I use XNODE from
System.Xml.Linq
XNode node = JsonConvert.DeserializeXNode(json,"root");
and here I converted the json string
finally I printed it :
Console.WriteLine(node.ToString());
don't forget to change it to "string" because anything appear on screen should be string.
HERE is the library and namespaces I used at top :
first I downloaded json.et library from : click on your assembly >
.select 'Manage Nuget Packages for Solution'
.click 'online', in the search box type 'newtonsoft'
.click 'Install' on 'Json.NET' (probably, what your looking for might be in another package, I'll ask you to track it down).
and then type these namespaces up :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml;
using System.IO;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using Newtonsoft.JsonResult;
using System.Xml.Linq;