实例如下所示
importar com.alibaba.fastjson.json; importação com.alibaba.fastjson.jsonArray; importação com.alibaba.fastjson.jsonObject; importar io.swagger.models.authithithMesech; import java.ioexception; import.security.KeyMoGensception; importação; java.util.iterator;/*** Criado pelo administrador em 2017/4/21. */public class Test {public static void main (string [] args) lança exceção {// 第一种格式/*** [{"data": [{"Building_id": "***", "Building_num": "**"], "Door_Name": "**", "Electric", "**", "Room_Name" "": s = "[{/" success/": true,/" data/": [{/" Building_id/":/" ***/",/" Building_num/":/" **/",/" Room_name/":/" **/",/" Door_name/":/" **/"/"]:/"; String b = s.substring (0, s.Length ()-1); String c = b.substring (1, b.Length ()); System.out.println (b+"b ___"); JsonObject jsonx = json.parseObject (c); JsonArray JA = jsonx.getjsonArray ("dados"); for (int i = 0; i <ja.size (); i ++) {jsonObject jo = ja.getjsonObject (i); String Building_id = Jo.getString ("Building_id"); System.out.println (Building_id+"Building_id >>>>>"); } // 第二种格式/***[{"senha": "*1234567890", "sucessor": "true"}]*/string s = "[{/" success/":/" true/",/" senha/":/"*1234567890/"}]"; String b = s.substring (0, s.Length ()-1); String c = b.substring (1, b.Length ()); System.out.println (c+"c ___"); JsonObject reagobj = jsonObject.FromObject (c); Nome da string = reagobj.getString ("senha"); System.out.println (nome+"nome ,,,,," "); String senha = jm.getString ("senha"); System.out.println (senha); System.out.println ("看看有没有值"+senha); // 第三种格式/*** {"Data": {"Access_token": "5A7040CCF66BAFD06ACD39B6F61C19230ABA426755509646D6DA23DDD9FB206" "Extires_Second" 365.000}: 36D6Da23ddd9fb206 "," Expires_Second "365.000}: 365}: 365}: 363d6ddddd9fb206". "rlt_msg": "成功"} */ string res = "{/" data/": {/" access_token/":/" 5A7040CCF66BAFD06ACD39B6F61C19230ABA4267555509646D6 da23ddd9fb206/",/" expires_second/": 36000},/" rlt_code/":/" hh0000/",/" rlt_msg/":/" 成功/"}"; JsonObject jsonObject = json.parseObject (res); Dados da string = jsonObject.getString ("dados"); JsonObject jsondata = json.parseObject (dados); String token = jsondata.getString("access_token");//第四种格式 /** * { "data ":{ "total ":23, "start ":0, "total_page ":3, "rows ":[{ "op_way ": "3 ", "user_mobile ": "15321918571 ", "op_time ":1493881391976, "pwd_no": 30}, {"op_way": "1", "op_time": 1493880995000, "pwd_no": 31}], "current_page": 1, "Page_size": 10}, "rlt_code": "hh0000" "" rl ": 10}," rlt_code ":" hh0000 "" "RT_" RL ":" res = "{/" data/": {/" total/": 23,/" start/": 0,/" total_page/": 3,/" linhas/": [{/" op_way/":/" 1/",/" op_time/": 149384964000, /"pwd_no/": 31}, {/"op_way/":/"3/",/"user_mobile/":/"18518517491/",/"op_time/": 1493884615032,/"pwd_no/": 30}, {}, {" ay/":/"3/",/"user_mobile/":/"18518517491/",/"op_time/":1493883836552,/"pwd_no/":30},{/"op_way/":/"1/",/"op_time/ ": 1493883294000,/" pwd_no/": 31}, {/" op_way/":/" 1/",/" op_time/": 1493883256000,/" pwd_no/": 31}, {/" op_way/"/" 3/"3/", " r_mobile/":/" 15321918571/",/" op_time/": 1493883015371,/" pwd_no/": 30}, {/" op_way/":/" 1/",/" op_time/": 149382007000, /"pwd_no/": 31}, {/"op_way/":/"3/",/"user_mobile/":/"15321918571/",/"op_time/": 149388149852,/"pwd_no/": 30}, {}, {" ay/":/" 3/",/" user_mobile/":/" 15321918571/",/" op_time/": 1493881391976,/" pwd_no/": 30}, {/" op_way/":/" 1/"/" optime//" : 1493880995000,/"pwd_no/": 31}],/"current_page/": 1,/"page_size/": 10},/"rlt_code/":/"hh0000/",/"rlt_msg/":/"成功/"} ""; JsonObject jsonObject = json.parseObject (res); Dados da string = jsonObject.getString ("dados"); JsonObject jsonObjects = json.parseObject (dados); JsonArray JA = JsonObjects.getjsonArray ("linhas"); for (int i = 0; i <ja.size (); i ++) {jsonObject jo = ja.getjsonObject (i); String op_way = jo.getString ("op_way"); String op_time = jo.getString ("op_time"); SimpledateFormatAmat MELLEDEFORMAT = new SimpleDateFormat ("AAAA-MM-DD HH: MM: SS"); long lt = novo longo (op_time); Data data = nova data (LT); res = SimpleDateFormat.Format (Data); String pwd_no = jo.getString ("pwd_no"); String user_mobile = jo.getString ("user_mobile"); System.out.println (op_way+res+pwd_no+user_mobile+"------------"); }}}以上这篇 Java 的 JsonObject 对象提取值方法就是小编分享给大家的全部内容了 , 希望能给大家一个参考 , 也希望大家多多支持武林网。