About the Jsonobject value Method GetString () and optstring ()

Source: Internet
Author: User
Tags try catch

With JSON so long, just found Jsonobject getstring () Hidden bombs!!!

 PublicMap<string, object>queryalmmonitorinfo (@RequestBody String jsonstr) {jsonobject json=Jsonobject.fromobject (JSONSTR); //Current page number        intCurrentPage =Json.getint (sysconstant.page); //number of bars per page        intPageSize =Json.getint (sysconstant.rows); Map<string, object> mape =NewHashmap<string, object>(); String Areaid= Json.getstring ("Areaids"); Jsonarray Areaids=Jsonarray.fromobject (Areaid); @SuppressWarnings ("Unchecked") List<String> areaidlist = (list<string>) jsonarray.tocollection (Areaids, String.class); String SYSANDEQP= Json.getstring ("eqplists"); List<String>eqplists; if("". Equals (SYSANDEQP)) {eqplists=NULL; }        Else{Jsonarray eqplist=Jsonarray.fromobject (SYSANDEQP); Eqplists= (list<string>) jsonarray.tocollection (Eqplist, String.class); } String Sysemsid= Json.getstring ("Sysemsid"); String Techtype= Json.getstring ("Techtype"); List<String>Sysemsids; if("". Equals (SYSEMSID)) {Sysemsids=NULL; }        Else {            /** Jsonarray sysemsidlist = Jsonarray.fromobject (SYSEMSID);             * Sysemsids = (list<string>) jsonarray.tocollection (sysemsidlist, * string.class); */string[] Arr= Sysemsid.split (","); Sysemsids=arrays.aslist (arr); } List<String>techtypes; if("". Equals (Techtype)) {Techtypes=NULL; }        Else {            /** Jsonarray techtypelist = Jsonarray.fromobject (Techtype);             * Techtypes = (list<string>) jsonarray.tocollection (techtypelist, * string.class); */string[] arr1= Techtype.split (","); Techtypes=arrays.aslist (ARR1); } String keyword= json.getstring ("keyword"); String Alarmlevel= Json.getstring ("Alarmlevel"); String Neemsid= Json.getstring ("Neemsid"); String Shelfemsid= Json.getstring ("Shelfemsid"); String Slotemsid= Json.getstring ("Slotemsid"); intCardemsid = Json.getint ("Cardemsid"); String isconf= Json.getstring ("isconf"); String Portemsid= Json.getstring ("Portemsid"); Pagevo Pagevo=Pageutil.assemblepagevo (CurrentPage, pageSize); Mape.put ("Keyword", keyword); Mape.put ("Alarmlevel", Alarmlevel); Mape.put ("Techtype", techtypes); Mape.put ("Areaid", areaidlist); Mape.put ("Sysemsid", Sysemsids); Mape.put ("Neemsid", Neemsid); Mape.put ("Shelfemsid", Shelfemsid); Mape.put ("Slotemsid", Slotemsid); Mape.put ("Cardemsid", Cardemsid); Mape.put ("Portemsid", Portemsid); Mape.put ("SYSANDEQP", eqplists); Mape.put ("Isconf", isconf); //new addition Condition 20180628Mape.put ("Isdamage", Json.optstring ("Isdamage")); Mape.put ("Techtypename", Json.optstring ("Techtypename")); Mape.put ("SysName", Json.optstring ("SysName")); Mape.put ("Netypename", Json.optstring ("Netypename")); Mape.put ("Alarmleveloriginal", Json.optstring ("Alarmleveloriginal")); Mape.put ("Alarmnetimestar", Json.optstring ("Alarmnetimestar")); Mape.put ("Alarmnetimeend", Json.optstring ("Alarmnetimeend")); Mape.put ("Ruledesc", Json.optstring ("Ruledesc")); Mape.put ("ProjectName", Json.optstring ("ProjectName")); Pagevo Respagevo=almmonitorservice.getnetworkscaleanalysis (Pagevo, mape); Map<string, object> map =NewHashmap<string, object>();        Map.put (Sysconstant.rows, Respagevo.getvolist ());        Map.put (Sysconstant.total, Respagevo.getrecordcount ()); returnmap; }

Project with the SPRINGMVC, the front end error after debugging for this method does not return a value, because this is someone else wrote the code and there is no try catch (here Express anger!!!) ), after 1.1 points debug found GetString () method for no reason thrown abnormal, asked the next degree Niang found this method has thunder: when there is no key in the jsonobject of the time to throw an exception, and optstring () will not, the front end is written by the custom condition query, The key in Jsonobject is not fixed, so instead of using the optstring () method, there is a judgment in the SQL MyBatis configuration that does not affect the query.

About the Jsonobject value Method GetString () and optstring ()

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.