我送通過AJAX JSON對象和Web API來我的服務器:JSON.NET錯誤讀取JObject
var data = [
["fdsfsd", "Kifdsfa", "fsdfsa", "fadsf", "fasdfsd", "fadsf", "fasdfsd"],
["2008", "-5", "11", "12", "13"],
["2009", "20", "-11", "14", "13"],
["2010", "30", "15", "-12", "readOnly"]
];
$.ajax({
url: '../webapi/Products',
type: 'POST',
dataType: "text",
data: "="+JSON.stringify(data),
success: function (test) {
alert(test);
},
error: function (test) {
alert("Error");
}
,所以我從服務器上的,我想用JSON.NET解析值AM:
public void Post([FromBody]string value)
{
JObject o = JObject.Parse(@value);
}
這引發異常:
Error reading JObject from JsonReader. Current JsonReader item is not an object:
StartArray. Path '', line 1, position 1.
爲什麼?價值似乎對我來說是正確的?
您是否在服務器上打印了值以檢查語法是否正確?我的猜測是,你得到一個JSON數組而不是一個JSON對象 – HashtagMarkus
是的,它似乎是數組。所以沒有辦法將它轉換爲JObject的權利?我該如何轉換這個數組到一個DataTable? – daniel