none
c# to jQuery replace " with double quote RRS feed

  • Question

  • I see this alot, but no topic actually helps me.

    My issue is simple, I save a JSON string to the database. It looks like this:

    [{\"Name\":\"Campaign types\",\"Value\":\"Emails\"},{\"Name\":\"Expiry date\",\"Value\":\"\"},{\"Name\":\"Originating continent\",\"Value\":\"Middle East\"},{\"Name\":\"Originating country\",\"Value\":\"Group\"}]

    Now, this inserts into the database (without the backslashes) as expected.
    The problem arises when I try to get the string back from the database in my controller, it comes back like this:

    '[{"Name":"Campaign types","Value":"Emails"},{"Name":"Expiry date","Value":""},{"Name":"Originating continent","Value":"Middle East"},{"Name":"Originating country","Value":"Group"}]'  

    Now, the problem is them ", they should be double quotes. How can i convert them so I can use $.parseJSON on that string?

    Cheers,

    r3plica

    Thursday, September 20, 2012 11:44 AM

Answers

  • It isn't as simple as that, it is c# that is returning the quotes.

    I solved it through jquery though with .replace(/"/g, '"')
    • Marked as answer by r3plica Thursday, September 20, 2012 1:58 PM
    Thursday, September 20, 2012 1:58 PM

All replies

  • Try:

    yourString.Replace(""", "\"");

     

    Noam B.



    Do not Forget to Vote as Answer/Helpful, please. It encourages us to help you...

    Thursday, September 20, 2012 12:10 PM
  • It isn't as simple as that, it is c# that is returning the quotes.

    I solved it through jquery though with .replace(/"/g, '"')
    • Marked as answer by r3plica Thursday, September 20, 2012 1:58 PM
    Thursday, September 20, 2012 1:58 PM
  • Hi r3plica,

      Welcome to MSDN Forum Support.

      I am glad to hear that you have solved your problem,and thank you for sharing your solution with us.

      Sincerely,

      Jason Wang


    Jason Wang [MSFT]
    MSDN Community Support | Feedback to us

    Monday, October 1, 2012 2:17 AM