コード例 #1
0
  public static void main(String[] args) throws Exception {
    InputStream is = ConvertJSONtoXMLNoHints.class.getResourceAsStream("sample-json.txt");
    String jsonData = IOUtils.toString(is);

    XMLSerializer serializer = new XMLSerializer();
    JSON json = JSONSerializer.toJSON(jsonData);
    serializer.setTypeHintsEnabled(false);
    String xml = serializer.write(json);
    System.out.println(xml);
  }
コード例 #2
0
 /**
  * json to xml {"node":{"key":{"@label":"key1","#text":"value1"}}} conver <o><node
  * class="object"><key class="object" label="key1">value1</key></node></o>
  *
  * @param json
  * @return
  */
 public static String jsontoXml(String json) {
   try {
     XMLSerializer serializer = new XMLSerializer();
     JSON jsonObject = JSONSerializer.toJSON(json);
     return serializer.write(jsonObject);
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }
コード例 #3
0
 @Test
 public void testJSONObjectToXMLTest002() {
   JSONObject jsonObject = JSONObject.fromObject(new Contact());
   try {
     XMLSerializer xml = new XMLSerializer();
     String xmlStr = xml.write(jsonObject);
     System.out.println("testJSONObjectToXMLTest002:" + xmlStr);
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
コード例 #4
0
ファイル: Utility.java プロジェクト: zhangyutao/vautotest
 public static String jsontoXml(byte[] josonSource) {
   String source = "";
   try {
     source = new String(josonSource, "gb2312");
   } catch (UnsupportedEncodingException e) {
     // TODO Auto-generated catch block
     e.printStackTrace();
   }
   XMLSerializer xmlSerializer = new XMLSerializer();
   JSON json = JSONObject.fromObject(source);
   ;
   return xmlSerializer.write(json).toString();
 }
コード例 #5
0
ファイル: Utility.java プロジェクト: zhangyutao/vautotest
 public static String jsontoXml(String jsonString) {
   XMLSerializer xmlSerializer = new XMLSerializer();
   JSONObject jsonobj = JSONObject.fromObject(jsonString);
   return xmlSerializer.write(jsonobj).toString();
 }