Java XML Sanitize sanitizeJson4XML(String jsonString)

Here you can find the source of sanitizeJson4XML(String jsonString)

Description

sanitizeJson4XML - Sanitize a JSON string so it converts to XML without error.

License

Apache License

Parameter

Parameter Description
jsonString - the JSON string to process.

Return

- an "XML safe" JSON string.

Declaration

public static String sanitizeJson4XML(String jsonString) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from   w  ww  . j a v  a  2s.  co m*/
     * sanitizeJson4XML - Sanitize a JSON string so it converts to XML without error.
     * 
     * @param jsonString    - the JSON string to process.
     * @return             - an "XML safe" JSON string.
     * 
     */
    public static String sanitizeJson4XML(String jsonString) {

        // Remove leading & trailing whitespace
        jsonString = jsonString.trim();

        // Handle anonymous object results
        if (!jsonString.startsWith("{")) {

            jsonString = "{\"Anonymous\":" + jsonString + "}";
        }

        return jsonString;
    }
}

Related

  1. sanitizeXML(String xml)
  2. SanitizeXmlString(String xml)
  3. sanitizeXmlTypeName(String name)