JsonResult parsing special chars as \u0027 (apostrophe)

后端 未结 3 1877
天命终不由人
天命终不由人 2020-12-18 05:51

I am in the process of converting some of our web \"services\" to MVC3 from WCF Rest.

Our old web services returned JSON from POCO\'s just fine using: [WebGet(

相关标签:
3条回答
  • 2020-12-18 06:29

    That shouldn't be any problem, as both representations are equivalent:

    var a = {"CategoryId":8,"SomeId":6,"Name":"Richie\u0027s House"};
    alert(a.Name);
    

    alerts Richie's House.

    0 讨论(0)
  • 2020-12-18 06:30

    Just do:

    yourObject.Name = yourObject.Name.replace("'", "\\u027");
    

    So, if you try to alert in javascript or show in a browser, it will appears like:

    Richie's House

    0 讨论(0)
  • 2020-12-18 06:33

    U+0027 is Unicode for apostrophe (')

    So, special characters are returned in Unicode but will show up properly when rendered on the page.

    0 讨论(0)
提交回复
热议问题