problems inserting html into a Json Java object

1

When inserting html content within an object Json

It is inserting a \ next to all the tags in the closing tags.

example:

input: obj.put("html","< head>< / head>"):

output: "< head>< \/ head>"

How can I ignore and not insert anything in the% s of% s?

    
asked by anonymous 28.12.2015 / 17:44

1 answer

1

Hello, do not worry about this character, by decoding JSON the system will remove it:

Here is an example of java :

public static void main(String[] args) {
    try {

        JSONObject jsonObject = new JSONObject();
        jsonObject.put("head","<head></head>");
        jsonObject.put("body","<body></body>");
        jsonObject.put("script","<script></script>");

        JSONObject novo = new JSONObject(jsonObject.toString());


        System.out.println(novo.get("head"));
        System.out.println(novo.get("body"));
        System.out.println(novo.get("script"));
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

See that it will print without the character!

Here is an example in Javascript , using the result set by java :

<html>
<head>
 <script src="https://code.jquery.com/jquery-1.10.2.js"></script><scripttype="text/javascript">
var obj = jQuery.parseJSON( '{"head":"<head><\/head>","body":"<body><\/body>","script":"<script><\/script>"}' );
alert( obj.head);
alert( obj.body);
alert( obj.script);
</script>
</head>
</html>

Here too the character is removed!

    
28.12.2015 / 19:16