Struts2 json return extra \ backward slash

My Struts2 is currently returning this:


I want this:

<action name="dayofcartoon" method="dayofcartoon" class="">
    <result name="json" type="json"> 
        <param name="excludeNullProperties">true</param>
        <param name="root">

1 Answer

  1. Cary- Reply


    Many JSON encoders escape chars / as \/. It's not incorrect but is not mandatory. It's related with the /> char combination and allow JSON string to be embeded in Javascript code.

    If you are using this JSON with Javascript code, you shouldn't be worried about it because Javascript handles it correctly. Both \/ and / are equivalents.

    If you should return unescaped response from your Struts2 action then try to force to your JSON encoder to not escape the slash char.

    Here you've got a good article talking about this topic:

Leave a Reply

Your email address will not be published. Required fields are marked *

You can use these HTML tags and attributes <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>