When Fastjson encounters the big write segment

Source: Internet
Author: User

A headache has been encountered in the project. When using Fastjson to deserialize the following JSON, get the object property is always null (such as), may be careful friend a look to know where the problem is, yes! The problem is that the first letter of the returned field is capitalized. Fastjson parsing is the use of reflection to assign values to objects through SETXXX (), which is why our JavaBean must raise the price of GetXXX () and the Setxxx () method.
Knowing where the problem is, we have to find a way to solve it. First think of is Baidu, but after a while not fruit. Database and server are not to do their own, to change the database and the server is not realistic, only on the Android, the service is to make the return of the JSON field of the first letter lowercase, or change the field in the data table, OK, here, it is not suspense, the solution is very simple, Directly to the JSON string toLowerCase () and then converted to Jsonobject, then JavaBean can be all lowercase processing.
Key code:jsonobject jobject = new Jsonobject (Resource.tolowercase (Locale.getdefault ()));

{"res": "1", "Index_banner": [{"Ad_name": "Mobile phone scrolling big picture One", "Ad_link": "/huodong/fabuhui.ht ML "," Ad_code ":"/uploads/image/20140910/20140910172048_31579.jpg "}, {" Ad_name ":" Phone Scroll to switch Five "," Ad_link ":" http://m.toptuu.com/Huodong/danye.html "," Ad_code ":"/uploads/image/20140906/201            40906084953_94943.jpg "}, {" Ad_name ":" Mobile phone scroll switch Four "," Ad_link ":"/huodong/dingzhi.html ", "Ad_code": "/uploads/image/20140906/20140906085053_90516.jpg"}, {"Ad_name": "Mobile phone scrolling switch three        "," Ad_link ":"/huodong/jiu.html "," Ad_code ":"/uploads/image/20140906/20140906085138_32961.jpg " }, {"Ad_name": "Mobile phone scrolling big Picture II", "Ad_link": "/huodong/jy.html", "Ad_code": "/uploads /image/20140910/20140910152954_72484.jpg "}, {" Ad_name ":" Phone switch 0 "," ad_link ":"/huodon         G/xifeng.html ",   "Ad_code": "/uploads/image/20140830/20140830115112_40561.jpg"}]} 

The solution is very simple, but it really makes me ponder for a long time, as long as the problem is worth documenting, will always help others.

When Fastjson encounters the big write segment

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.