Json格式 及编写处理类
Posted heibaimao123
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Json格式 及编写处理类相关的知识,希望对你有一定的参考价值。
以下是一组json样本:
{"HeWeather6":[{"basic":{"cid":"CN101270107","location":"郫都","parent_city":"成都","admin_area":"四川","cnty":"中国","lat":"30.80875206","lon":"103.88784027","tz":"+8.00"},"update":{"loc":"2018-08-22 07:45","utc":"2018-08-21 23:45"},"status":"ok","now":{"cloud":"50","cond_code":"104","cond_txt":"阴","fl":"24","hum":"95","pcpn":"0.0","pres":"1007","tmp":"22","vis":"30","wind_deg":"171","wind_dir":"南风","wind_sc":"1","wind_spd":"4"},"daily_forecast":[{"cond_code_d":"300","cond_code_n":"101","cond_txt_d":"阵雨","cond_txt_n":"多云","date":"2018-08-22","hum":"74","mr":"16:55","ms":"02:42","pcpn":"5.0","pop":"80","pres":"1005","sr":"06:35","ss":"19:38","tmp_max":"31","tmp_min":"21","uv_index":"6","vis":"14","wind_deg":"-1","wind_dir":"无持续风向","wind_sc":"1-2","wind_spd":"7"},{"cond_code_d":"101","cond_code_n":"101","cond_txt_d":"多云","cond_txt_n":"多云","date":"2018-08-23","hum":"64","mr":"17:42","ms":"03:31","pcpn":"5.0","pop":"80","pres":"1006","sr":"06:36","ss":"19:36","tmp_max":"33","tmp_min":"22","uv_index":"6","vis":"19","wind_deg":"-1","wind_dir":"无持续风向","wind_sc":"1-2","wind_spd":"11"},{"cond_code_d":"101","cond_code_n":"305","cond_txt_d":"多云","cond_txt_n":"小雨","date":"2018-08-24","hum":"76","mr":"18:24","ms":"04:22","pcpn":"5.0","pop":"79","pres":"1005","sr":"06:36","ss":"19:35","tmp_max":"32","tmp_min":"23","uv_index":"3","vis":"18","wind_deg":"-1","wind_dir":"无持续风向","wind_sc":"1-2","wind_spd":"7"}],"lifestyle":[{"type":"comf","brf":"较不舒适","txt":"白天天气多云,同时会感到有些热,不很舒适。"},{"type":"drsg","brf":"炎热","txt":"天气炎热,建议着短衫、短裙、短裤、薄型T恤衫等清凉夏季服装。"},{"type":"flu","brf":"少发","txt":"各项气象条件适宜,发生感冒机率较低。但请避免长期处于空调房间中,以防感冒。"},{"type":"sport","brf":"较适宜","txt":"天气较好,较适宜进行各种运动,但因天气热,请适当减少运动时间,降低运动强度。"},{"type":"trav","brf":"较适宜","txt":"天气较好,温度较高,天气较热,但有微风相伴,还是比较适宜旅游的,不过外出时要注意防暑防晒哦!"},{"type":"uv","brf":"中等","txt":"属中等强度紫外线辐射天气,外出时建议涂擦SPF高于15、PA+的防晒护肤品,戴帽子、太阳镜。"},{"type":"cw","brf":"较适宜","txt":"较适宜洗车,未来一天无雨,风力较小,擦洗一新的汽车至少能保持一天。"},{"type":"air","brf":"中","txt":"气象条件对空气污染物稀释、扩散和清除无明显影响,易感人群应适当减少室外活动时间。"}]}]}
JSON是一种优秀的文本信息的表现格式,具体语法如下:
- 数据在名称/值对中
- 数据由逗号分割
- 大括号保存对象
- 中括号保存数组
JSON值可以是:
- 数字
- 字符串
- 逻辑值
- 数组
- 对象
- null
isJSON()的编写:
清除多余的空格和换行符——遍历字符串,对于不是在成对双引号之间的空格和换行符删除。
检查符号是否正确
- 检查整体的格式是否正确;"名称":值
名称被英文双引号包围;
名称与值之间是一个英文冒号;
值有三种形式——被英文双引号包围、被中括号或大括号包围、数字或逻辑值或null
名称、冒号、值之间及前后可能出现空格或换行符
以上是关于Json格式 及编写处理类的主要内容,如果未能解决你的问题,请参考以下文章
mybatis 处理数组类型及使用Json格式保存数据 JsonTypeHandler and ArrayTypeHandler