最近在写一个yupoo应用,基于ajax的,所以需要将xml转换为json,在网上搜索后找到两个不错的类
PHP服务端的XMLtoJSON
<?php
require_once("xml2json.php");
echo Xml2json::transformXmlStringToJson(xml_data);
?>
<!-- HTML --> <head> <script type="text/javascript" src="xml2json.js"></script> ... </head>
// Javascript // A simple call - myXML is a string containing your XML: myJsonObject=xml2json.parser(myXML); // A 2:nd, optional, parameter is "tags not to convert" - for example <b> and <i>: myJsonObject=xml2json.parser(myXML,'b,i'); // A 3:rd, optional, parameter gives us a string showing us the JSON structure // instead of the actual JSON object: myString=xml2json.parser(myXML,'','html'); // - use "compact" for output without linebreaks or tabbing // - use "normal" for output with linebreaks and tabbing // - use "html" for a html representation

Posted in
Tags: