Struts2 json return extra \ backward slash

My Struts2 is currently returning this:

[{"pathlocation":"http:\/\/103.231.125.106\/nesos\/cartoon\/151020183506download.jpeg"}]

I want this:

[{"pathlocation":"http://103.231.125.106/nesos/cartoon/151026121150download.jpeg"}]
<action name="dayofcartoon" method="dayofcartoon" class="foo.bar.AdminInfoAction">
    <result name="json" type="json"> 
        <param name="excludeNullProperties">true</param>
        <param name="root">
         commissioner_info
        </param>            
     </result>
</action> 

1 Answer

  1. Cary- Reply

    2019-11-16

    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: http://andowebsit.es/blog/noteslog.com/post/the-solidus-issue/

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>