项目需要,转出XMLSerializer转出的xml字符串需要去掉<D type="string">app</D>中间的type=“string”;
关键设置如下setTypeHintsEnabled(false)
String xml = null;
String resStr = "{'TX':'WS01001', 'T':'0', 'D':'app', 'V':'1.0.0', 'id':'1', 'startCity':'"
+ "杭州" + "', 'arriveCity':'" + "北京" + "'}";
JSONObject res = JSONObject.fromObject(resStr);
XMLSerializer xs = new XMLSerializer();
xs.setTypeHintsEnabled(false);
xml = xs.write(res);
System.out.println(xml);
结果入下:
<?xml version="1.0" encoding="UTF-8"?>
<o><D type="string">app</D><T type="string">0</T><TX type="string">WS01001</TX><V type="string">1.0.0</V><arriveCity type="string">北京</arriveCity><idtype="string">1</id><startCity type="string">杭州</startCity></o>