Send JSON data with Ajax, with data type list, com.alibaba.fastjson.JSONException:syntax error, expect {, actual error, POS 1 This type of error
is generally a data format problem
First we have to understand the JSON data format
In JSON, objects are surrounded with {}, and mappings are denoted by ":", and the set or array is surrounded by []
For example, a Java class has a JSON format of
{ Name 1: value 1, Name 2: Value 2}
The JSON format for a list is
[ {Name 1: value, Name 2: Value 2},{Name 1: value, Name 2: Value 2}]
Here you need to pay attention to a problem, using the "=" Connection key value in the map, instead of ":", and the list is not the same
Also, the tostring method must be overridden in the Java class in which we need to convert, otherwise the default ToString () method is called automatically, and only one string can be obtained: "class name [email Protected]+hashcode", and can't get internal data.
The ToString () method, which is automatically generated with Eclipse, is also not a JSON-compliant format requirement.
The auto-generated format is
Public String toString () { return "Test [itemlist=" + Itemlist + ", address=" + address + ", total=" + Tot Al + "]";}
Must be modified to this format
Public String toString () { return "{\" itemlist\ ": \" "+ itemlist +" \ ", \" addr Ess\ ": \" "+ Address +" \ ", \" total\ ": \" "+ Total +" \ "}";}
We can use the Json.parsearray method to get the list we need in the background.
Fastjson Processing Data Errors Com.alibaba.fastjson.JSONException:syntax error, expect {, actual error, POS 1