2012-08-10 108 views
0

我目前正在使用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

回答

0

It reaches the server side code where i wish to read it as it was sent and i get the below Error:

你转换StringJSONArray阅读之前在服务器端?

这样,

JSONArray array = new JSONArray(json_data); 
-1

GSON节选要与POJO映射的关键,像

public class Test { 
    private List<Type> attr; 
    } 

的东西,这ATTR必须存在于JSON {” ATTR“{”CompanyName“:”IOK“,”ContactName“:”Maria Anders“,”ContactTitle“:”Sales Head“,”Address“:”Obere Str.57“,”City“ ,“国家”:“德国”},
{“CompanyName”:“Dubiou”,“ContactName”:“Ana Trujillo”,“ContactTitle”:“销售经理”,“地址”:“Avda。德拉Constitucin 2222“,”城市“:”墨西哥D.F.“,”国家“:”墨西哥“}
]}

相关问题