Fastjson Processing Data Errors Com.alibaba.fastjson.JSONException:syntax error, expect {, actual error, POS 1

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.