实例如下所示 :
Import com.alibaba.fastjson.json; Import com.alibaba.fastjson.jsonArray; Import com.alibaba.fastjson.jsonObject; Import io.swagger.models.Auth.in; Import Java.io.ioxception; Java.util.iterator;/*** Erstellt von Administrator am 2017/4/21. */public class test {public static void main (String [] args) löst Ausnahme aus {// 第一种格式/*** [{"Daten": [{"Building_id": "***", "bauen_num": "**", "tous_name": "**", "Electric": "**", "Room_name". s = "[{/" Erfolg/": true,/" data/": [{/" Building_id/":/" ***/",/" Building_num/":/" **/",/" Room_name/":/" **/",/" Tür_Name/":/" **/"Electric/". 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 ("Daten"); für (int i = 0; i <ja.size (); i ++) {jsonObject jo = ja.getJsonObject (i); String Building_id = jo.getString ("bauen_id"); System.out.println (bauen_id+"bauen_id >>>>>"); } // 第二种格式/***[{"Passwort": "*1234567890", "Erfolg": "True"}]*/String S = "[{/" Erfolg/":/" true/",/" Passwort/":/"*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); String name = reagobj.getString ("Passwort"); System.out.println (Name+"Name ,,,,,,"); String password = jm.getString ("Passwort"); System.out.println (Passwort); System.out.println ("看看有没有值"+Passwort); //第三种格式/*** { "data ": { "access_token ": "5a7040ccf66bafd06acd39b6f61c19230eaba426755509646d6da23ddd9fb206 ", "expires_second ": 36000 }, "rlt_code ": "HH0000 ", "rlt_msg ":" 成功 "} */ String res = "{/" data/": {/" access_token/":/" 5A7040CCF66BAFD06ACD39B6F61C19230EABA426755509646D6 DA23DDD9FB206/",/" expires_second/": 36000},/" rlt_code/":/" hh0000/",/" rlt_msg/":/" 成功/"}"; JsonObject jsonObject = json.ParseObject (res); String data = jsonObject.getString ("Daten"); JsonObject jSondata = json.ParseObject (Daten); 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 ","rlt_msg ": "成功 "}*/ String res = "{/" data/": {/" Total/": 23,/" start/": 0,/" Total_Page/": 3,/" rows/": [{/" op_way/":/" 1/",/" op_time/": 149384964000, /"pwd_no/": 31}, {/"op_way/":/"3/",/"user_mobile/":/"18518517491/",/"op_time/": 1493884615032,/"pwd_no/": 30}, {/"OP_W ay/":/" 3/",/" user_mobile/":/" 18518517491/",/" op_time/": 1493883836552,/" pwd_no/": 30}, {/" opway/":/" 1/"Op_Time/" OP_TIME/"OP_TIME/" OP_TIME/"OP_TIME/" "OP_TIME/" "OP_TIME/":/"OP_TIME/" - "OP_TIME/":/"OP_TIME/":/"OP_TIME/":/"OP_TIME/" - "OP_TIME/" " ": 1493883294000,/" pwd_no/": 31}, {/" op_way/":/" 1/",/" op_time/": 1493883256000,/" pwd_no/": 31}, {/" op_way/":/" 3/" r_mobile/":/" 15321918571/",/" op_time/": 149383015371,/" pwd_no/": 30}, {/" op_way/":/" 1/",/" Optime/": 149382007000,, /"pwd_no/": 31}, {/"op_way/":/"3/",/"user_mobile/":/"15321918571/",/"op_time/": 1493881498520,/"pwd_no/": 30}, {/"OP_W ay/":/" 3/",/" user_mobile/":/" 15321918571/",/" op_time/": 1493881391976,/" pwd_no/": 30}, {/" Opway/":/" 1/"Op_Time/" : 1493880995000,/"pwd_no/": 31}],/"current_page/": 1,/"page_size/": 10},/"rlt_code/":/"hh0000/",/"rlt_msg/":/"成功/"} "; JsonObject jsonObject = json.ParseObject (res); String data = jsonObject.getString ("Daten"); JsonObject jsonObjects = json.ParseObject (Daten); JsonArray ja = jsonObjects.getjsonArray ("Reihen"); für (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"); SimpledateFormat SimpleDateFormat = new SimpledateFormat ("yyyy-mm-dd hh: mm: ss"); langes lt = neu long (op_time); Datum Datum = neues Datum (LT); res = SimpledateFormat.Format (Datum); 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 对象提取值方法就是小编分享给大家的全部内容了 , 希望能给大家一个参考 , 也希望大家多多支持武林网。 也希望大家多多支持武林网。