可以转成Xml再处理[C#] 纯文本查看 复制代码 // <summary>
/// json字符串转换为Xml对象
/// </summary>
/// <param name="sJson"></param>
/// <returns></returns>
public static XmlDocument Json2Xml(string sJson)
{
//XmlDictionaryReader reader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(sJson), XmlDictionaryReaderQuotas.Max);
//XmlDocument doc = new XmlDocument();
//doc.Load(reader);
JavaScriptSerializer oSerializer = new JavaScriptSerializer();
Dictionary<string, object> Dic = (Dictionary<string, object>)oSerializer.DeserializeObject(sJson);
XmlDocument doc = new XmlDocument();
XmlDeclaration xmlDec;
xmlDec = doc.CreateXmlDeclaration("1.0", "gb2312", "yes");
doc.InsertBefore(xmlDec, doc.DocumentElement);
XmlElement nRoot = doc.CreateElement("root");
doc.AppendChild(nRoot);
foreach (KeyValuePair<string, object> item in Dic)
{
XmlElement element = doc.CreateElement(item.Key);
KeyValue2Xml(element, item);
nRoot.AppendChild(element);
}
return doc;
}
参考http://www.sufeinet.com/thread-2733-1-1.html
另外2.0下也可以使用DoNet2.0 需要借助于Newtonsoft.Json.dll吧
[C#] 纯文本查看 复制代码 using System;
using System.IO;
using System.Text;
using Newtonsoft.Json;
namespace OfflineAcceptControl.UCTools
{
public class JsonTools
{
// 从一个对象信息生成Json串
public static string ObjectToJson(object obj)
{
return JavaScriptConvert.SerializeObject(obj);
}
// 从一个Json串生成对象信息
public static object JsonToObject(string jsonString, object obj)
{
return JavaScriptConvert.DeserializeObject(jsonString, obj.GetType());
}
}
}
下载地址http://json.codeplex.com/
或者直接在这里下载
Json50r8.zip
(6.12 MB, 下载次数: 133)
|