Json字符串对errrors无效 [英] Json string not valid with errrors

查看:88
本文介绍了Json字符串对errrors无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是一个Json字符串

当我粘贴它(第一个和最后一个字符,即双引号,被删除)

JSON Formatter&验证器 [ ^ ]

用于验证。

Below is a Json string
When I pastes it (the 1st and last characters, namely the double quote, are removed) in
JSON Formatter & Validator[^]
for validation.

JsonString = "{\"ownerSysId\":\"MyIMG\",\"applicationId\":31000,\"uploadFiles\":[{\"id\":2121,\"path\":\"\\\\jServer.local\\gisprod\\Photos\\engineering\\A01\\A01\\PF(2)\\2019\",\"fileName\":\"\\E029089_02-21-2019_085353.png\",\"bearing\":\"none\",\"createdDate\":\"2019-01-03T08:59\"},{\"id\":2141,\"path\":\"\\\\jServer.local\\gisprod\\Photos\\engineering\\B02\\B02\\SHFT(VB4)\\2017\",\"fileName\":\"\\C020533_02-28-2019_131017.png\",\"bearing\":\"none\",\"createdDate\":\"2017-04-27T12:37\"}]}";



收到的错误是


The errors received are

Strings should be wrapped in double quotes.



使用NotePad删除所有单背-slash,文字喜欢以下内容:


Using NotePad to remove all of the single back-slash, the text likes that below:

{"ownerSysId":"MyIMG","applicationId":31000,"uploadFiles":[{"id":2121,"path":"\\\\jServer.local\\gisprod\\Photos\\engineering\\A01\\A01\\PF(2)\\2019","fileName":"\\E029089_02-21-2019_085353.png","bearing":"none","createdDate":"2019-01-03T08:59"},{"id":2141,"path":"\\\\jServer.local\\gisprod\\Photos\\engineering\\B02\\B02\\SHFT(VB4)\\2017","fileName":"\\C020533_02-28-2019_131017.png","bearing":"none","createdDate":"2017-04-27T12:37\"}]}



它得到验证。

我尝试过多个字符串函数来删除单个反斜杠,但效果不佳。如果你能为这个问题提供帮助,我将不胜感激。



我尝试过:



尝试


it gets validated.
I have tried multiple string function to remove single back-slash, but not effective. I will appreciate if you can help for this issue.

What I have tried:

Tried

JsonValue.Replace("\\","")

但不工作

尝试

but not working
Tried

JsonValue.TrimStart('\\').TrimEnd('\\')

但没有工作

推荐答案

你的最终字符串错过了收盘

\



\2017-04-27T12:37}]};
Your final string misses a closing
\"

\"2017-04-27T12:37}]}";


字符串中不存在这些反斜杠。它们只存在于您的源代码中代码。



根据您的设置,您可能还会在调试器中看到它们。



但是如果您将字符串输出到控制台,您将看到该字符串包含完全有效的JSON:

C#String Escape | C#Online编译器| .NET小提琴 [ ^ ]

Those backslashes don't exist in your string. They only exist in your source code.

Depending on your settings, you might also see them in the debugger.

But if you output the string to the console, you'll see that the string contains perfectly valid JSON:
C# String Escape | C# Online Compiler | .NET Fiddle[^]
string JsonString = "{\"ownerSysId\":\"MyIMG\",...
Console.WriteLine(JsonString);

输出:

{"ownerSysId":"MyIMG",...


因为和\在C / C ++ / C#语言中有特殊含义,它们在源代码中出现时会被转义。

每种编程语言都使用这种技术在源代码中的字符串中包含特殊字符。 br />
所以你在源代码中看到的json字符串不是编译后的可执行文件。
Because " and \ have special meaning in C/C++/C# languages, they are escaped when they appear in source code.
Every programming language use this technique to include special chars in a string in source code.
So the json string you see in source code is not what is in executable after compilation.


这篇关于Json字符串对errrors无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆