Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/303.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 将带有POST的JSON发送到服务器进行解析-为什么此ajax调用失败?_C#_Jquery_Ajax_Asp.net Mvc_Json - Fatal编程技术网

C# 将带有POST的JSON发送到服务器进行解析-为什么此ajax调用失败?

C# 将带有POST的JSON发送到服务器进行解析-为什么此ajax调用失败?,c#,jquery,ajax,asp.net-mvc,json,C#,Jquery,Ajax,Asp.net Mvc,Json,因此,我向服务器发送一个JSON字符串,以便通过jQueryAjax进行解析。我从Glosbe字典的API中获取JSON。大多数情况下,它都能按预期工作,但某些JSON会失败。有趣的是,在这些情况下,我得到了一个“内部服务器错误”,但当我试图调试应用程序时,似乎控制器甚至没有被调用。我不知道这怎么可能 以下是我的看法: $.ajax({ url: '@Url.Action("Parse", "GetMeaning")', dataType: "js

因此,我向服务器发送一个JSON字符串,以便通过jQueryAjax进行解析。我从Glosbe字典的API中获取JSON。大多数情况下,它都能按预期工作,但某些JSON会失败。有趣的是,在这些情况下,我得到了一个“内部服务器错误”,但当我试图调试应用程序时,似乎控制器甚至没有被调用。我不知道这怎么可能

以下是我的看法:

        $.ajax({
        url: '@Url.Action("Parse", "GetMeaning")',
        dataType: "json",
        data: "ValueToParse=" + jsonToSend, //maybe it's better to send a json instead of a string
        type: 'POST',
        async: false,
        contentType: "application/json; charset=utf-8",
        success: function (data) {
            //pass the data to the server for parsing

            //alert("sendJsonToServer successful, sended " + JSON.stringify(json1) + "got back: " + data);
            setMeaningofExpression(expression, data);
            $('#expressionTranslations').html(expressionsAsString());
        },
        error: function (xhr, status, error) {
            alert('sendJsonToServer error, tried to send ' + JSON.stringify(jsonToSend) + 'problem: ' + status + " " + error);
        }
    });
控制器:

    [HttpPost]
    public JsonResult Parse(String ValueToParse)
    {

            return Json(Parser.Parse(ValueToParse).ToArray());

    }
失败的Json示例:

{"result":"ok","authors":{"1":{"U":"//en.wiktionary.org","id":1,"N":"en.wiktionary.org"},"20":{"U":"//www.slowniki.org.pl/","id":20,"N":"Jerzy Kazojc"},"86":{"U":null,"id":86,"N":"wiki"},"25018":{"U":"//glosbe.com","id":25018,"N":"GlosbeResearch"},"2695":{"U":"//dumps.wikimedia.org/enwiktionary/latest/enwiktionary-latest-pages-articles.xml.bz2","id":2695,"N":"Wiktionary"}},"dest":"hun","phrase":"cat","tuc":[{"authors":[86],"meaningId":-4164218657921168000,"meanings":[{"text":"member of Felidae","language":"eng"},{"text":"domestic species","language":"eng"},{"text":"A common four-legged animal (Felis silvestris) that is often kept as a household pet.","language":"eng"},{"text":"ket","language":"eng"}],"phrase":{"text":"macska","language":"hun"}},{"authors":[2695],"meaningId":-9072797188187576000,"meanings":[{"text":"domestic species","language":"eng"}],"phrase":{"text":"kandúr","language":"hun"}},{"authors":[1],"meaningId":4566464096976442400,"meanings":[{"text":"domestic species","language":"eng"}],"phrase":{"text":"cica","language":"hun"}},{"authors":[25018],"meaningId":3489096155947903000,"phrase":{"text":"hány","language":"hun"}},{"authors":[25018],"meaningId":-557814434056432960,"phrase":{"text":"krapek","language":"hun"}},{"authors":[20],"meaningId":-2600640194269463000,"phrase":{"text":"muksó","language":"hun"}},{"authors":[25018],"meaningId":-4572067174236314000,"phrase":{"text":"rókázik","language":"hun"}},{"authors":[1],"meaningId":null,"meanings":[{"text":"An enthusiast or player of jazz.","language":"eng"}]},{"authors":[1],"meaningId":null,"meanings":[{"text":"(computing) A lsquo;catenate; program and command in Unix that reads one or more files and directs their content to an output device.","language":"eng"}]},{"authors":[1],"meaningId":null,"meanings":[{"text":"(slang, vulgar, African American Vernacular) A vagina; female external genitalia","language":"eng"}]},{"authors":[1],"meaningId":null,"meanings":[{"text":"(slang) To vomit something.","language":"eng"}]},{"authors":[1],"meaningId":null,"meanings":[{"text":"(Irish, informal) terrible, disastrous.","language":"eng"}]},{"authors":[1],"meaningId":null,"meanings":[{"text":"(archaic, uncountable) The game of ;trap and ball; (also called ;cat and dog;).","language":"eng"}]},{"authors":[1],"meaningId":null,"meanings":[{"text":"(slang) Any of a variety of earth-moving machines. (from their manufacturer Caterpillar Inc.)","language":"eng"}]},{"authors":[1],"meaningId":null,"meanings":[{"text":"raise anchor to cathead","language":"eng"}]},{"authors":[1],"meaningId":null,"meanings":[{"text":"(nautical) To flog with a cat-o-nine-tails.","language":"eng"}]},{"authors":[1],"meaningId":null,"meanings":[{"text":"vomit","language":"eng"}]},{"authors":[1],"meaningId":null,"meanings":[{"text":"(archaic) A sturdy merchant sailing vessel (now only in ;catboat;).","language":"eng"}]},{"authors":[1],"meaningId":null,"meanings":[{"text":"(slang) Prostitute. [from at least early 15th c.]","language":"eng"}]},{"authors":[1],"meaningId":null,"meanings":[{"text":"Any similar animal of the family Felidae, which includes lions, tigers, etc.","language":"eng"}]},{"authors":[1],"meaningId":null,"meanings":[{"text":"(nautical) Contraction of cat-o-nine-tails.","language":"eng"}]},{"authors":[1],"meaningId":null,"meanings":[{"text":"guy, fellow","language":"eng"}]},{"authors":[1],"meaningId":null,"meanings":[{"text":"(archaic, uncountable) The trap of the game of ;trap and ball;.","language":"eng"}]},{"authors":[1],"meaningId":null,"meanings":[{"text":"(slang) A person (usually male).","language":"eng"}]},{"authors":[1],"meaningId":null,"meanings":[{"text":"(nautical) To hoist (the anchor) by its ring so that it hangs at the cathead.","language":"eng"}]},{"authors":[1],"meaningId":null,"meanings":[{"text":"(computing slang) To dump large amounts of data on (an unprepared target) usually with no intention of browsing it carefully.","language":"eng"}]},{"authors":[1],"meaningId":null,"meanings":[{"text":"(derogatory) A spiteful or angry woman. [from earlier 13th c.]","language":"eng"}]},{"authors":[1],"meaningId":null,"meanings":[{"text":"A catfish.","language":"eng"}]},{"authors":[1],"meaningId":null,"meanings":[{"text":"A domesticated subspecies (Felis silvestris catus) of feline animal, commonly kept as a house pet. [from 8th c.]","language":"eng"}]},{"authors":[1],"meaningId":null,"meanings":[{"text":"(nautical) A strong tackle used to hoist an anchor to the cathead of a ship.","language":"eng"}]},{"authors":[1],"meaningId":null,"meanings":[{"text":"(computing) To apply the <b>cat</b> command to (a file).","language":"eng"}]},{"authors":[1],"meaningId":null,"meanings":[{"text":"strong tackle used to hoist an anchor to the cathead of a ship","language":"eng"}]},{"authors":[1],"meaningId":null,"meanings":[{"text":"A catamaran.","language":"eng"}]}],"from":"eng"}
{“result”:“ok”,“authors”:{“1”:{“U”:”//en.wiktionary.org”,“id”:1,“N”:“en.wiktionary.org”},“20”:{“U”:”//www.slowniki.org.pl/,“id”:20,“N”:“Jerzy Kazojc”},“86”:{“U”:null,“id”:86,“N”:“wiki”},“25018”:{“U”:/glosbe.com”,“id”:25018,“N”:“N”:“Jerzy Kazojc”},“2695”:“U”:“//dumps.wikimedia.org/enwiktionary/latest/enwiktionary latest pages articles.xml.bz2”,“id”:2695,“N”:“Wiktionary”},“dest”:“hun”,“短语”:“cat”,“tuc”:[{“authors”:[86],“meaningId”:-4164218657921168000,“含义”:[{“文本”:“猫科成员”,“语言”:“eng”},{“文本”:“家养物种”,“语言”:“eng(Felis silvestris)经常被当作家庭宠物饲养。“,”语言“:”eng“,”文本“:”ket“,”语言“:”eng“,”短语“,”文本“:”macska“,”语言“:”hun“,”作者“:”2695“,”意指“:-9072797188187576000”,意思“:”:“[”文本“:”家养物种“,”语言“:”eng“,”短语“,”短语“:”{”文本“:”坎杜尔“,”语言“:”,”作者“:”hun“,”意指“,”作者“,”意指“,”1“,”意指“:456644096976442400,“含义”:[{“文本”:“国内物种”,“语言”:“英语”}],“短语”:“{“文本”:“cica”,“语言”:“hun”},{“作者”:[25018],“含义ID”:3489096155947903000,”短语:{“文本”:“哈尼”,“语言”:“hun”},{“作者”:[25018],“含义ID”:-5578144340564960,”短语:{“文本”:“克拉佩克”,“语言”:“hun”},{“作者”},{:-26006401942694633000,“短语”:{“文本”:“muksó”,“语言”:“hun”},{“作者”:[25018],“meaningId”:-4572067174236314000,“短语”:{“文本”:“rókázik”,“语言”:“hun”},{“作者”:[1],“meaningId”:null,“含义”:[{“文本”:“爵士乐爱好者或演奏者”,“语言”:“engUnix中的一种lsquo;catenate;程序和命令,它读取一个或多个文件并将其内容定向到输出设备。,“语言”:“eng”},{“authors”:[1],“meaningId”:null,意思是[{“text”:(俚语,粗俗,非洲裔美国人的方言)阴道;女性外生殖器”,“语言”:“eng”},{“authors”:[1],“meaningId”:null,意思是[{“text”“,”语言“:”eng“}]},{”作者“:”,”意为“:”空,“意为“{”文本“:”(爱尔兰语,非正式)可怕的,灾难性的“,”语言“:”eng“}]},{”作者“:”,”意为“:”文本“:”(古语,不可数)陷阱和球的游戏;(也称为猫和狗;),”语言“:”eng“}},{”作者“,”意为“,”意为“:”,”意为“:”,“{:null,“含义”:[{“文本”:(俚语)各种土方机械中的任何一种。(来自其制造商卡特彼勒公司),“语言”:“eng”}],{“作者”:[1],“meaningId”:null,“含义”:[{“文本”:“锚定猫头”,“语言”:“eng”}],{“作者”:[1],“meaningId”:null,“含义”:[{“文本”:(航海)用九尾猫鞭打。”,“语言”:“eng”{“authors”:[1],“meaningId”:null,“meaningId”:[1],“meaningId”:null,“meaningId”:null,“meaningId”:[1],“meaningId”:[1],“meaningId”:null,“meaningId”:null,“meaningId”:null,“meanings”:[“text”:(俚语)妓女。[至少从15世纪早期开始],“语言”:英语:{authors:[1],“meaningId”:空,意思是:{text:“猫科任何类似的动物,包括狮子、老虎等”,“语言:{eng”},{authors:[1],“meaningId”:空,意思是:[{“text:”(航海)猫九尾的收缩。,“语言:{eng”},{“authors:[1],“meaningId”:空,意思是:{“text:”盖伊,同伴“,”语言:{eng}},{authors:[1],“meaningId”:null,意思:{{“text”:(古语,不可数)游戏的陷阱;陷阱和球;,“language”:“eng}},},{“authors”:[1],“meaningId”:null,意思是:{“text”:(俚语)一个人(通常是男性)。“,“language”:“eng},{“authors”:[1],“meaningId”:null,意思是:{“text”:(航海)起锚)“语言”:“eng”}},{“作者”:[1],“meaningId”:null,“含义”:[{“文本”:(计算俚语)在(未准备好的目标)上转储大量数据,通常无意仔细浏览。”,“语言”:“eng”},{“作者”:[1],“meaningId”:null,“含义”:[{“文本”:(贬义)恶意或愤怒的女人。[从公元前13世纪],“语言”:“eng”},{“作者”:[1],“meaningId”:null,“含义”:[{“文本”:“鲶鱼”。,“语言”:“eng”},},{“作者”:[1],“meaningId”:null,“含义”:[{“文本”:“猫科动物的家养亚种(猫科动物),通常作为家养宠物。[公元前8世纪],“语言”:“{”作者:“[1],“meaningId”:null,“含义”:[{“文本”:(航海)用于将锚提升到船的猫头上的强力滑车。”,“语言”:“eng”}],{“作者”:[1],“meaningId”:null,“含义”:[{“文本”:(计算)将cat命令应用于(文件)。”,“语言”:“eng”}},{“作者”:[1],“meaningId”:null,“含义”:[{“文本”:”用于将锚提升到船的猫头上的强力滑车,“,”语言“:”eng“}]},“{”作者“:[1],”含义“:[{”文本“:”双体船“,”语言“:”eng“}]}],”from“:”eng“}”

我也遇到过类似的问题。试试这个:

var ValueToSend = {'': jsonToSend };

$.ajax({
    url: '@Url.Action("Parse", "GetMeaning")',
    data: ValueToSend 
    type: 'POST',
    success:....

请注意,我删除了
contentType
dataType
,并且json字符串包含在一个属性名为空的对象中。本文提供了帮助:还可以确保在服务器上正确运行路由;我建议将URL保留为硬编码,直到您确定所有内容都正常工作为止,因此我将替换它
url:'@url.Action(“Parse”,“GetMeaning”)
与实际路由。

问题在于ASP.NET被阻止