关于项目自动化测试架构的改良计划 - XML格式转为json格式
因为讨论下来,最终的DataProvider格式需要是一个json格式,所以我们还必须提供方法吧xml格式转为json格式,现在很多框架比如json-lib框架能很轻易的完成这个任务了。 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 /** * This class will read the xml file and then change it to a json object *@author cwang58 *@created date: Jun 9, 2013 */ public class XMLJSONConverter { /** * This method will convert the xml to json object * @param xml the xml string * @return the json string */ public static String xml2JSON(String xml){ XMLSerializer xmlSerializer = new XMLSerializer(); JSON json = xmlSerializer.read(xml); return json.toString(); } .. } 就几行代码,很容易读懂。 本文转自 charles_wang888 51CTO博客,原文链接:http://blog.51cto.com/supercharles888/1221759,如需转载请自行联系原作者