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