日期:2014-05-16 浏览次数:21126 次
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json;
namespace test写入XML
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
func();
}
public void func()
{
string jsonString = "{\"url\":\"http://www.baidu.com\"}";
//json 的字符串需要按照这个格式 书写,否则会报错
string json = @"{""?xml"": {""@version"": ""1.0"",""@standalone"": ""no"" },""root"":" + jsonString + "}";
if (!string.IsNullOrEmpty(json))
{
XmlDocument doc = JsonConvert.DeserializeXmlNode(json);
doc.Save("aaa.xml");
}
}
}
}