可读性
JSON和XML的可读性可谓不相上下,XML略占上风。
可扩展性
XML天生有很好的扩展性,JSON当然也有,没有什么是XML能扩展,JSON不能的。
编码难度
XML有丰富的编码工具,比如Dom4j、JDom等,JSON也有json.org提供的工具,但是JSON的编码明显比XML容易许多,即使不借助工具也能写出JSON的代码,可是要写好XML就不太容易了。
解码难度
XML的解析得考虑子节点父节点关系,让人头昏眼花,而JSON的解析难度几乎为零。
流行度
XML已经被业界广泛的使用,而JSON才刚刚开始,但在Ajax领域,JSON凭借自身的优势有可能最终取代XML。
JSON转换为XML格式:DEMO:
需要jar包:json-lib-2.4-jdk15.jar,xom-1.1.jar,ezmorph-1.0.6.jar,commons-logging-1.1.1.jar,
commons-lang-2.5.jar,commons-collections-3.2.1.jar,commons-collections-3.1.jar,commons-beanutils-1.8.3.jar
package cn.song;
import net.sf.json.JSONArray;
import net.sf.json.JSONObject;
import net.sf.json.xml.XMLSerializer;
public class Json2Xml {
/**
* @param args
*/
public static void main(String[] args) {
String json = "[{\"Product_ID\":\"0501010093\",\"Product_name\":\"美素(金装美素乐)奶粉二段900g\",\"Product_Pic\":\"jpg\",\"Product_URL\":\"http\",\"Product_price\":216},"
+ "{\"Product_ID\":\"0501010093\",\"Product_name\":\"美素(金装美素乐)奶粉二段900g\",\"Product_Pic\":\"jpg\",\"Product_URL\":\"http\",\"Product_price\":216},"
+ "{\"Product_ID\":\"0501010093\",\"Product_name\":\"美素(金装美素乐)奶粉二段900g\",\"Product_Pic\":\"jpg\",\"Product_URL\":\"http\",\"Product_price\":216},]";
JSONArray jsonObject = JSONArray.fromObject(json);
XMLSerializer xmlSerial = new XMLSerializer();
String xml = xmlSerial.write(jsonObject);
System.out.println(xml);
}
}
分享到:
相关推荐
XML to JSON and JSON to XML converter
- JQuery - jquery.json2xml.js - jquery.xml2json.js 2. XML 字符串转换成 JSON 对象 $.xml2json(str); 3. JSON 对象转换成 XML 字符串 $.json2xml(obj);
自己写的json与xml互转工具 简单实用
js下xml转json和json转xml
jquery.json2xml.js&&jquery.xml2json.js在jQuery的基础上实现json与xml的相互转换
delphi代码json和xml格式互转
Json和Xml离线格式化工具
xml 与 json 格式的相互转换,采用javascript 实现。
json与xml互相转换工具类
jQuery xml-to-json xml转JSON jQuery实现xml转JSON插件 有demo和相关文档
用于在C++结构体和json/xml之间互相转换, bson在xbson中支持。 只需要头文件, 无需编译库文件。 具体可以参考example的例子
XML and (the more popular) JSON let you organize data in textual formats. This book introduces you to these technologies along with Java APIs for integrating them into your Java code. This book ...
g关于Json介绍,用JSON替换XML
json2xml的代码。
C# Json转Xml 或 Xml转Json 使用详细说明及资源 支持框架2.0以上 控件Newtonsoft.Json.dll内容详细包含源代码示例
JSON-XML相关jar包.rar
string JSON = XmlToJSON.Converter.XmlToJSON(xmlDoc); 示例: XmlDocument doc = new XmlDocument(); //doc.LoadXml(@"<root>aaa</root>"); doc.Load(@"C:\xxx.xml"); // Convert XML to a JSON string string ...
java工程源码实现xml和json的互转,工程已包含所jar包:commons-beanutils-1.7.0.jar、commons-collections-3.1.jar、commons-lang-2.5.jar、commons-logging.jar、ezmorph-1.0.3.jar、json-lib-2.4-jdk15.jar、xom-...
json和xml比较,让你充分了解开发底层必备知识!
xml字符串转换json格式 可用于微信小程序xml字符串转换json格式 安装 npm方式安装 npm install --save xmlstring2json bower方式安装 bower install xmlstring2json 用法示例: bookstore.xml文件 <title>...