我目前正在使用Gson和JQWidgets。com.google.gson.JsonSyntaxException:java.lang.IllegalStateException:預期的BEGIN_ARRAY,但是STRING
第1步:使用gson使用它的api將JSON數據以格式發送到網格,作爲JQWidgets支持的行。
[
{ "CompanyName": "Alfreds Futterkiste", "ContactName": "Maria Anders", "ContactTitle": "Sales Representative", "Address": "Obere Str. 57", "City": "Berlin", "Country": "Germany" },
{ "CompanyName": "Ana Trujillo Emparedados y helados", "ContactName": "Ana Trujillo", "ContactTitle": "Owner", "Address": "Avda. de la Constitucin 2222", "City": "Mxico D.F.", "Country": "Mexico" },
{ "CompanyName": "Antonio Moreno Taquera", "ContactName": "Antonio Moreno", "ContactTitle": "Owner", "Address": "Mataderos 2312", "City": "Mxico D.F.", "Country": "Mexico" }
]
步驟2:在對JSP網格行的數據前端被改變, 這些變化在一個臨時數組如下推動。
//這裏創建了全局陣列,和數據變更 //網格的每行中進行被放入陣列
var tempArray = new Array();
{
var data = $('#jqxgridreq').jqxGrid('getrowdata', args.rowindex);
var arr = $.makeArray(data);
tempArray.push(data);
}
後來又跟着是 - >無功json_string = JSON .stringify(tempArray); 這裏,數據與創建json字符串時的上述示例數據相同。
第三步:更改後的數據發送到服務器AJAX調用,如下
[
{ "CompanyName": "IOK", "ContactName": "Maria Anders", "ContactTitle": "Sales Head", "Address": "Obere Str. 57", "City": "Berlin", "Country": "Germany" },
{ "CompanyName": "Dubiou", "ContactName": "Ana Trujillo", "ContactTitle": "Sales Manager", "Address": "Avda. de la Constitucin 2222", "City": "Mxico D.F.", "Country": "Mexico" }
]
到達服務器端的代碼,我想讀它,因爲它被送往,我也得到了以下錯誤:
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_ARRAY but was STRING
請幫助並建議如何解決此問題。
感謝和問候 Ranchs