【问题标题】:C# Json formating is not validated by online Json validator [duplicate]在线 Json 验证器未验证 C# Json 格式[重复]
【发布时间】:2018-07-25 17:57:35
【问题描述】:

C# Webservice 正在生成这个 json

[{\"Question\":\"This is the Question no 0\",\"Answer1\":\"This is Answer1 of Question 0\",\"Answer2\":\"This is Answer2 of Question 0\",\"Answer3\":\"This is Answer3 of Question 0\",\"Answer4\":\"This is Answer4 of Question 0\",\"Correct\":1},{\"Question\":\"This is the Question no 1\",\"Answer1\":\"This is Answer1 of Question 1\",\"Answer2\":\"This is Answer2 of Question 1\",\"Answer3\":\"This is Answer3 of Question 1\",\"Answer4\":\"This is Answer4 of Question 1\",\"Correct\":1},{\"Question\":\"This is the Question no 2\",\"Answer1\":\"This is Answer1 of Question 2\",\"Answer2\":\"This is Answer2 of Question 2\",\"Answer3\":\"This is Answer3 of Question 2\",\"Answer4\":\"This is Answer4 of Question 2\",\"Correct\":1}]

但在线 json 验证器在 json 字符串中显示错误。 Angular 也没有正确解析 json 字符串并给出错误。我正在使用 Newtonsoft json 序列化来生成 json 字符串。请帮忙。

【问题讨论】:

    标签: javascript c# json angular wcf


    【解决方案1】:

    看起来您在 .net 代码中将对象双重编码为​​ JSON。首先,您将一个对象编码为 JSON 并获取一个字符串。

    console.log(
      "normal encoded:",
      JSON.stringify({hello:"world"})
    );
    console.log(
      "double encoded:",
      JSON.stringify(JSON.stringify({hello:"world"}))
    );

    问题可能不在 ES 中,而在您的 .net 代码中。您的问题的解决方案很可能是here

    【讨论】:

      猜你喜欢
      • 2020-05-05
      • 1970-01-01
      • 1970-01-01
      • 2013-10-24
      • 2016-06-29
      • 2020-12-22
      • 1970-01-01
      • 2019-10-17
      • 2016-08-27
      相关资源
      最近更新 更多