简体   繁体   English

Json反序列化期间的解析错误

[英]Parsing Error during Json Deserialization

Im new here! 我是新来的! I want to ask some help about my code, I used XML to set my query. 我想向我的代码寻求帮助,我使用XML来设置查询。 <add key="atstr" value="{vquery: EXECUTE spSomething @str1 = 'A', @str2 = 'B'}" />

Now on my c# code: 现在在我的C#代码上:

if(region.Length > 0)
{
     foreach(var item in strX.Split(','))
     exQuery = ConfigurationManager.AppSettings["atstr"];
     dynamic dynaATSTR = JObject.Parse(exQuery);
     Console.WriteLine(dynaATSTR.vquery);
     break;
}

I got this error message: After parsing a value an unexpected character was encountered. 我收到此错误消息:解析值后,遇到意外字符。

I believed it has something to do with the "'" (Apostrophe). 我相信这与“'”(撇号)有关。 Because I believed it breaks the string inside the XML file while Json read the string as different and breaks every string. 因为我相信它会破坏XML文件中的字符串,而Json会以不同的方式读取字符串并破坏每个字符串。

Can someone help me with it? 有人可以帮我吗? I looked and tried some codes from this community but nothing works. 我查看并尝试了该社区的一些代码,但是没有任何效果。

Your code is effectively doing this: 您的代码有效地做到了这一点:

if(region.Length > 0)
{
     foreach(var item in strX.Split(','))
     {
         exQuery = ConfigurationManager.AppSettings["atstr"];
     }
     dynamic dynaATSTR = JObject.Parse(exQuery);
     Console.WriteLine(dynaATSTR.vquery);
     break;
}

Im pretty sure thats not what you intended.. 我很确定那不是你想要的。

also try: 也尝试:

<add key="atstr" value="{vquery: \"EXECUTE spSomething @str1 = 'A', @str2 = 'B'\"}" />
<add key="atstr" value="{ &quot;vquery&quot;: &quot;EXECUTE spSomething @str1 = 'A', @str2 = 'B'&quot;}" />

参考: https : //msdn.microsoft.com/zh-cn/library/ms256152(v=vs.110).aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM