【问题标题】:JSON - How to allow spacial characters in JSON? [closed]JSON - 如何在 JSON 中允许特殊字符? [关闭]
【发布时间】:2013-09-18 12:24:43
【问题描述】:
Response.ContentType = "text/plain";

System.IO.Stream inptStrm = Request.InputStream;

byte[] bytes = new byte[inptStrm.Length];

int i = inptStrm.Read(bytes, 0, Convert.ToInt32(inptStrm.Length));

string Input = Encoding.UTF8.GetString(bytes);
JsonTextParser parsor = new JsonTextParser();

JsonObject jsonObj = parsor.Parse(Input);

我的输入字符串是 :::::

{
  "function":"addwhy",

  "lastname":"\"", // this line


}

我的代理也尝试将其转换为 UTF8 格式,但我的代码在用于解析器时产生了错误。

【问题讨论】:

    标签: c# .net json


    【解决方案1】:

    它应该只是一个反斜杠,如...

    "shopname":"\"\""
    "lastname": "\"\"",
    

    如果你添加这个 JSON...

    {
        "function": "addwhy",
        "firstname": "firstname",
        "lastname": "\"\"",
        "dob": "8/8/2001",
        "dop": "testplace",
        "street": "teststreet",
        "nr": "testnr",
        "postcode": "123456",
        "place": "testplace",
        "telephone": "telephone",
        "incidentid": "1",
        "Aangehoudendoor": "testAangehoudendoor",
        "Waar": "testWaar",
        "DayTime": "Monday,
        6: 48PM",
        "createdby": "1",
        "updatedby": "0",
        "shopId": "1",
        "witneesid": "1",
        "op": "",
        "om": "testom"
    }
    

    ..到JSONLint validator,你会看到验证成功。

    【讨论】:

    • 哦,正如问题所暗示的那样......?
    • @ParinParikh 为什么需要在数据库中插入引号?
    【解决方案2】:

    您的数据有误。客户端应在创建 JSON 之前转义引号。

    对 JavaScript 使用 JSON.stringify 或关注 Escape Quotes in Objective-C

    【讨论】:

      【解决方案3】:

      您应该注意响应中的引号,而不是在解析时出错(即,避免格式错误的 JSON 响应)。尝试将引号作为:

        ....
        ....
        "lastname":"""", 
        "dob":"8/8/2001",
        "dop":"testplace",
        ....
        ....
      

      【讨论】:

      • 错误是什么?
      猜你喜欢
      • 2014-09-25
      • 1970-01-01
      • 2022-01-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-09
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多