实例如下所示 :
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.seSecurity.KeyManagementException; import java.security.nosuchalgorithgorithmect; java.util.iterator;/*** Creado por el administrador el 2017/4/21. */public class test {public static void main (string [] args) lanza la excepción {// 第一种格式/*** [{"data": [{"edificio_id": "***", "edificio_num": "**", "door_name": "**", "electric": "**", "room_name": "**" "," éxito ": verdadero}/stre s = "[{/" éxito/": true,/" data/": [{/" edificio_id/":/" ***/",/" edificio_num/":/" **/",/" habitación_name/":/" **/",/" door_name/":" **/",/" electric/":" **/"}]"; Cadena B = S.Substring (0, S.Length ()-1); Cadena C = B.Substring (1, B.Length ()); System.out.println (b+"b ___"); JsonObject jsonx = json.parseObject (c); JSONArray JA = JSONX.GETJSONArray ("datos"); for (int i = 0; i <ja.size (); i ++) {jsonObject Jo = ja.getJsonObject (i); String Building_id = Jo.getString ("edificio_id"); System.out.println (edificio_id+"edificio_id >>>>>"); } // 第二种格式/***[{"contraseña": "*1234567890", "éxito": "true"}]*/string s = "[{/" éxito/":/" true/",/" contraseña/":/"*1234567890/"}]"; Cadena B = S.Substring (0, S.Length ()-1); Cadena C = B.Substring (1, B.Length ()); System.out.println (c+"c ___"); JsonObject reagobj = jsonObject.FromObject (c); Name de cadena = reagobj.getString ("contraseña"); System.out.println (nombre+"nombre ,,,,,,"); Cadena contraseña = jM.getString ("contraseña"); System.out.println (contraseña); System.out.println ("看看有没有值"+contraseña); //第三种格式/*** { "data ": { "access_token ": "5a7040ccf66bafd06acd39b6f61c19230eaba426755509646d6da23ddd9fb206 ", "expires_second ": 36000 }, "rlt_code ": "HH0000 ", "rlt_msg": "成功"} */ string res = "{/" data/": {/" access_token/":/" 5A7040CCF66BAFD06ACD39B6F61C19230ABA426755509646D6 da23ddd9fb206/",/" expires_second/": 36000},/" rlt_code/":/" hh0000/",/" rlt_msg/":/" 成功/"}"; JsonObject jsonObject = json.parseObject (res); String data = jsonObject.getString ("datos"); JsonObject JSondata = JSON.ParseObject (datos); String token = jSondata.getString ("access_token"); // 第四种格式/*** {"data": {"total": 23, "inicio": 0, "total_page": 3, "filas": [{"op_way": "3", "user_mobile": "15321918571", "tiempo": 149381381 "" pwd_no ": 30}, {" op_way ":" 1 "," op_time ": 1493880995000," pwd_no ": 31}]," current_page ": 1," page_size ": 10}," rlt_code ":" hh000000 "," rlt_msg ":" 成功 " res = "{/" data/": {/" total/": 23,/" inicio/": 0,/" total_page/": 3,/" Rows/": [{/" op_way/":/" 1/",/" op_time/": 1493888444000, /"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/",/" Opte_Time// ": 1493883294000,/" pwd_no/": 31}, {/" op_way/":/" 1/",/" op_time/": 1493883256000,/" pwd_no/": 31}, {/" op_way/":/" 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/": 1493881498520,/"pwd_no/": 30}, {/" 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 ("datos"); JsonObject jsonObjects = json.parseObject (datos); JSONArray JA = jsonObjects.getJsonArray ("filas"); for (int i = 0; i <ja.size (); i ++) {jsonObject Jo = ja.getJsonObject (i); Cadena op_way = Jo.getString ("op_way"); Cadena op_time = Jo.getString ("op_time"); SimpleDateFormat SimpleDateFormat = new SimpleDateFormat ("yyyy-mm-dd hh: mm: ss"); long lt = new Long (op_time); Fecha fecha = nueva fecha (LT); res = SimpleDateFormat.Format (fecha); Cadena pwd_no = Jo.getString ("pwd_no"); Cadena user_mobile = Jo.getString ("user_mobile"); System.out.println (OP_WAY+RES+PWD_NO+USER_MOBILE+"-------------"); }}}以上这篇 java 的 jsonobject 对象提取值方法就是小编分享给大家的全部内容了 , 希望能给大家一个参考 也希望大家多多支持武林网。