JSON request failing because of line breaks, how to escape them?

Posted by mrblah on Stack Overflow See other posts from Stack Overflow or by mrblah
Published on 2009-06-15T23:39:17Z Indexed on 2010/04/11 11:03 UTC
Read the original article Hit count: 1030

Filed under:
|

Hi,

My JSON request seems to be failing because of line breaks (I am programatically weaving my own JSON string).

How can I escape for line breaks?

{"rc": "200", "m" : "", "o": "<div class='s1'>
            <div class='avatar'>                    
                <a href='\/asdf'>asdf<\/a><br \/>
                <strong>0<\/strong>
            <\/div>
            <div class='sl'>
                <p>
                    444444444
                <\/p>
            <\/div>
            <div class='clear'>
            <\/div>                        
        <\/div>"}

string jsonString = BuildJSON(someCollection).Replace(@"/", @"\/");

© Stack Overflow or respective owner

Related posts about asp.net-mvc

Related posts about JSON