Fastjson Error Solution details Com.alibaba.fastjson.JSONException:syntax error, expect {, actual EOF, POS 1410

Source: Internet
Author: User

Reason:

The array passed by the front end is too complex, but this problem occurs, the front end uses Vue Axios, sends the request, the backend Java receives the code, realizes the front end separation

Backend on the receiving Fastjson receive JSON, for business processing, backend controller status:

1 /**2      * 3 * <p>4 * <p> Add Order5      *6      * @returnObject7      */8 @ResponseBody9@RequestMapping (value = "/addorder",//TenMETHOD =requestmethod.post) One      PublicObject AddOrder (@RequestBody basesinglelist basesinglelist) { A  -         returnOrderservice.addorder (basesinglelist); -  the}
View Code

Front-end send JSON style

1 {2"Singleorderlist":[3         {4"Ordername": "Tang 1",5"Orderphone": "13245124512",6"Contact": "Send",7"Telephony": "7845120231111",8"Provinceid": 31,9"Cityid": 3101,Ten"RegionID": 310108, One"Address": "Add by default Don", A"UserId": "C6f53705451b497580ef093c0ff5", -"Serieid": "1", -"TrueTime": "2018-04-27", the"Overtime": "2019-04-27", -"Monthlyrent": 6000, -"Datecount": 12, -"PackageId": "3e449fb4b4a489fce1475c4577fb6", +"Applicationarea": "Ssswww", -"Total": "219000", +"Modularidnum":[ A                 { at"ItemId": "9b744dc99e2904d96ab1af5", -"Modularnum": 3 -                 } -             ] -         }, -         { in"Ordername": "Tang 1", -"Orderphone": "13245124512", to"Contact": "Send", +"Telephony": "7845120231111", -"Provinceid": 31, the"Cityid": 3101, *"RegionID": 310108, $"Address": "Add by default Don",Panax Notoginseng"UserId": "B4f13b97580ef093c0ff5", -"Serieid": "1", the"TrueTime": "2018-04-27", +"Overtime": "2019-04-27", A"Monthlyrent": 6000, the"Datecount": 12, +"PackageId": "3b4b4a489fce1475c4577fb6", -"Applicationarea": "Ssswww", $"Total": "219000", $"Modularidnum":[ -                 { -"ItemId": "09932da9b744dc99e295", the"Modularnum": 3 -                 }Wuyi             ] the         } -     ] Wu}
View Code

Solution:

The controller enters the data normally, decomposes the data and re-sends the business logic in the SERVICEIMPL layer:

(1) When the data is passed in as Jsonobject, it is passed by the following method

1 /**2 * Place Order3      *4      * @parambasesinglelist5      * @returnObject6      */7 @Override8      PublicObject AddOrder (basesinglelist basesinglelist) {9 TenString Linearray =jsonarray.tojsonstring (basesinglelist); OneHashMap Parsemap = Json.parseobject (linearray,hashmap.class); A  -list<singleorder> singleorderlist = Json.parsearray (Json.parseobject (Linearray). getString ("SingleOrderList" ), Singleorder.class); -          the           for(Singleorder singleorder:singleorderlist) { -  - System.out.println (Singleorder.getuserid ()); -          } +}
View Code

(2) When data is passed to map

1 /**2 * Place Order3      *4      * @parambasesinglelist5      * @returnObject6      */7 @Override8      PublicObject AddOrder (basesinglelist basesinglelist) {9 Ten  One  Amap<string, object> map =NewHashmap<string, object>(); -Map.put ("Count", 2); -Map.put ("Studentlist", basesinglelist); theString JSON = json.tojsonstring (map,true); -  -  -HashMap Parsemap = Json.parseobject (JSON, HashMap.class); +List<basesinglelist> StudentList1 = (list<basesinglelist>) parsemap.get ("Basesinglelist"); -  +           for(Singleorder singleorder:singleorderlist) { A            at System.out.println (Singleorder.getuserid ()); -   } -  -}
View Code

Reference documents:

73612224

Fastjson Error Solution details Com.alibaba.fastjson.JSONException:syntax error, expect {, actual EOF, POS 1410

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.