:
import com.alibaba.fastjson.json; import com.alibaba.fastjson.jsonArray; import com.alibaba.fastjson.jsonObject; import io.swagger.models.auth.in; import java.io.ioexception; import java.security.keymanivationException; import java.security.nosuchalgorithe java.util.iterator; / ** * créé par l'administrateur le 2017/4/21. * / Public Class Test {public static void main (String [] args) lève une exception {// 第一种格式 / *** [{"data": [{"Building_id": "***", "Building_Num": "**", "Door_name": "**", "Electric": "**"] S = "[{/" Success / ": true, /" data / ": [{/" Building_id / ": /" *** / ", /" Building_Num / ": /" ** / ", /" room_name / ": /" ** / ", /" Door_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 ("data"); pour (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 >>>>>"); } // 第二种格式 / ** * [{"mot de passe": "* 1234567890", "Success": "true"}] * / String S = "[{/" Success / ": /" true / ", /" mot de passe / ": /" * 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 ("mot de passe"); System.out.println (nom + "Name ,,,,,,"); String mot de passe = jm.getString ("mot de passe"); System.out.println (mot de passe); System.out.println ("看看有没有值" + mot de passe); // 第三种格式 / *** {"data": {"Access_Token": "5A7040CCF66BAFD06ACD39B6F61C19230EABA4267555509646D6DA23DDD9FB206", "Expires_second": 36000}, "RLT_CODE" "rlt_msg": "成功"} * / chaîne res = "{/" data / ": {/" access_token / ": /" 5a7040ccf66bafd06acd39b6f61c19230aaba426755509646d6 da23ddd9fb206 / ", /" expires_second / ": 36000}, /" rlt_code / ": /" hh0000 / ", /" rlt_msg / ": /" 成功 / "}"; JSONObject JSONObject = JSON.ParseObject (RES); String data = jsonObject.getString ("data"); JSONObject JSondata = JSON.ParseObject (données); String token = jSondata.getString ("Access_token"); // 第四种格式 / ** * {"data": {"Total": 23, "start": 0, "total_page": 3, "lignes": [{"op_way": "3", "user_mobile": "15321918571", "op_time": 143881391918571 "," op_time ": 143881391918571", "op_time": 1493881391918571 "," OP_TIME ": 143881391918571", "OP_TIM "pwd_no": 30}, {"op_way": "1", "op_time": 1493880995000, "pwd_no": 31}], "current_page": 1, "page_size": 10}, "rlt_code": "hh0000", "rlt_msg": "成功"} res = "{/" data / ": {/" total / ": 23, /" start / ": 0, /" total_page / ": 3, /" lignes / ": [{/" op_way / ": /" 1 / ", /" op_time / ": 1493884964000, / "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}, {/" op_way / ": /" 1 / ", /" op_time / " ": 1493883294000, /" pwd_no / ": 31}, {/" op_way / ": /" 1 / ", /" op_time / ": 1493883256000, /" pwd_no / ": 31}, {/" op_way / ": /" 3 / ", /" usage use r_mobile / ": /" 15321918571 / ", /" op_time / ": 1493883015371, /" pwd_no / ": 30}, {/" op_way / ": /" 1 / ", /" op_time / ": 1493882007000, / "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}, {/" op_way / ": /" 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 ("data"); JSONObject JSONObjects = JSON.ParseObject (DATA); JSONArray ja = jsonObjects.getJSonArray ("Rows"); pour (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"); long lt = new long (op_time); Date de date = nouvelle date (LT); res = simpledateFormat.format (date); 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 对象提取值方法就是小编分享给大家的全部内容了 , 希望能给大家一个参考 , 也希望大家多多支持武林网。