简体   繁体   English

尝试将JSON数据发送到服务器时出现语法错误或访问冲突异常

[英]Syntax error or access violation Exception when trying to send JSON Data to Server

I try to send a JSON data to a server using c#. 我尝试使用c#将JSON数据发送到服务器。 this is my code for posting data: 这是我发布数据的代码:

 private static string PostJSONData(string JSONdata, Uri url)
    {
        try
        {
            var httpWebRequest = (HttpWebRequest)WebRequest.Create(url);
            httpWebRequest.ContentType = "text/json";
            httpWebRequest.Method = "POST";

            using (var streamWriter = new StreamWriter(httpWebRequest.GetRequestStream()))
            {
                streamWriter.Write(JSONdata);
                streamWriter.Flush();
                streamWriter.Close();
            }
            var httpResponse = (HttpWebResponse)httpWebRequest.GetResponse();
            using (var streamReader = new StreamReader(httpResponse.GetResponseStream()))
            {
                var result = streamReader.ReadToEnd();
                return result;
            }

        }
        catch (Exception ex)
        {
            throw ex;
        }
    }

my JSON data is like this : 我的JSON数据是这样的:

{"Key":"auth_token","Value":""},
{"Key":"request_id","Value":"14104"},
{"Key":"_number","Value":"TAQ422924"},
{"Key":"Customer","Value":"Some Customer"},
{"Key":"first_date","Value":"2014-10-24T15:52:21"}]

when I try to send data, at line 当我尝试发送数据时,

var result = streamReader.ReadToEnd();

there is an error with this description 此描述有误

Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; 致命错误:消息为“ SQLSTATE [42000]”的未捕获的异常“ PDOException”:语法错误或访问冲突:1064 SQL语法有错误; check the manual that corresponds to your MySQL server version for the right syntax to use near ',,,,,,,,,,,,,,,,,) ) LIMIT 1' at line 1' in /var/www/clients/client0/web16/web/library/Zend/Db/Statement/Pdo.php:228 Stack trace: /var/www/clients/client0/web16/web/library/Zend/Db/Statement/Pdo.php(228): PDOStatement-execute(Array /var/www/clients/client0/web16/web/library/Zend/Db/Statement.php(320): Zend_Db_Statement_Pdo-_execute(Array) . . . 检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以便在/ var / www /中的第1行的',,,,,,,,,,,,,,,,,,)))LIMIT 1'附近使用clients / client0 / web16 / web / library / Zend / Db / Statement / Pdo.php:228堆栈跟踪:/var/www/clients/client0/web16/web/library/Zend/Db/Statement/Pdo.php(228 ):PDOStatement-execute(Array /var/www/clients/client0/web16/web/library/Zend/Db/Statement.php(320):Zend_Db_Statement_Pdo-_execute(Array)。。

whats this error for??? 这个错误是什么? Its from a php page , I dont use any php page. 它来自php页面,我不使用任何php页面。

ContentType for json is "application/json" and not "text/json". json的ContentType是“ application / json”,而不是“ text / json”。 The server may be treating you data as text rather than json. 服务器可能会将您的数据视为文本而不是json。 You json data is also missing the leading square bracket '[' 您的json数据也缺少前导方括号'['

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

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