JSON格式不正确,响应错误 [英] JSON Is Not Well Formed Response Error
本文介绍了JSON格式不正确,响应错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试创建一个c#控制台应用程序,并将JSON消息发送到站点,然后获取响应. 我的数据似乎可以发送,但是尝试读取响应时出现错误.
我需要更改什么才能阅读响应并确定好坏?
私有无效的PerformJSONPost() { var httpWebRequest =(HttpWebRequest)WebRequest.Create("http://requestb.in/12frf661"); httpWebRequest.ContentType ="application/json"; httpWebRequest.Method ="POST"; var jsonReader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(@"{"安全):{" UsernameToken":{"UsernameToken":" redrobin","Password","fahidsma!",}","System.Xml.XmlDictionaryReaderQuotas()"; } var httpResponse =(HttpWebResponse)httpWebRequest.GetResponse(); 使用(var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); }
解决方案
也许,您对代码进行了一次try/catch,以便您可以更好地了解原因.
I am attempting to create a c# console app and send a JSON message to a site, and get the response back. My data appears to send okay, but I get an error when attempting to read the response.
What do I need to alter in order to be able to read the response and determine if good or bad?
private void PerformJSONPost() { var httpWebRequest = (HttpWebRequest)WebRequest.Create("http://requestb.in/12frf661"); httpWebRequest.ContentType = "application/json"; httpWebRequest.Method = "POST"; var jsonReader = JsonReaderWriterFactory.CreateJsonReader(Encoding.UTF8.GetBytes(@"{ ""Security"": { ""UsernameToken"": { ""Username"": ""redrobin"", ""Password"": ""fahidsma!"" } }"), new System.Xml.XmlDictionaryReaderQuotas()); } var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse(); using (var streamReader = new StreamReader(httpResponse.GetResponseStream())) { var result = streamReader.ReadToEnd(); }
解决方案
Maybe, you put a try/catch around the code so that you might get better information as to the why.
这篇关于JSON格式不正确,响应错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文