实例如下所示:
com.alibaba.fastjson.json; Import com.alibaba.fastjson.jsonarray; Import com.alibaba.fastjson.jsonobject; Import io.swagher.models.auth.in; Import java.io.ioexception; Import java.security.keuritymanimenceception; Import java.security.nesurity.nesurity.nesurity.nesuritymexcherception; Java.util.iterator;/***は、2017/4/21に管理者によって作成されました。 */public class test {public static void main(string [] args)throws Exception {// s = "[{/" success/":true、/" data/":[{/" building_id/":/" ***/"、/" building_num/":/" **/"、/" room_name/":/" **/"、/" door_name/":/" **/"、/"/"/" **/"**/"}] ";文字列b = S.Substring(0、S.Length()-1);文字列c = b.substring(1、b.length()); system.out.println(b+"b ___"); jsonobject jsonx = json.parseobject(c); jsonarray ja = jsonx.getjsonarray( "data"); 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 >>>>"); } //第二种格式/***[{"password": "*1234567890"、 "success": "true"}]*/string s = "[{/" success/":/" true/"、/" password/":/"*1234567890/"}]";文字列b = S.Substring(0、S.Length()-1);文字列c = b.substring(1、b.length()); system.out.println(c+"c ___"); jsonobject reagobj = jsonobject.fromobject(c);文字列名= reagobj.getString( "password"); System.out.println(name+"name ,,,,,");文字列パスワード= jm.getString( "password"); System.out.println(パスワード); System.out.println( "看看有没有值"+パスワード); //第三种格式/*** {"data":{"access_token": "5A7040CCF66666666ACD06ACD39B6F61C19230EABA426755509646D6DA23DDD9FB206"、 "expires_second":36000} ":"成功 "} */ string res = "{/" data/":{/" Access_token/":/" 5A7040CCF66666ACD06ACD39B6F61C19230EABA426755509646D6D6 DA23DDD9FB206/"、/" expires_second/":36000}、/" rlt_code/":/" hh0000/"、/" rlt_msg/":/"成功/"}"; jsonobject jsonobject = json.parseobject(res);文字列data = jsonobject.getString( "data"); jsonobject jsondata = json.parseobject(data); string token = jsondata.getString( "Access_token"); // "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、/" rows/":[{/" 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/":149383836552、/" pwd_no/":30}、{/" op_way/":/" 1/"1/" ":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/":1493882007000、 /"pwd_no/":31}、{/"op_way/":/"3/"、/"user_mobile/":/"15321918571/"、/"op_time/":149381498520、/"pwd_no/":30}、{/"op_w ay/":/" 3/"、/" user_mobile/":/" 15321918571/"、/" op_time/":149381391976、/" pwd_no/":30}、{/" op_way/":/" 1/"1/" :1493880995000、/"pwd_no/":31}]、/"current_page/":1、/"page_size/":10}、/"rlt_code/":/"hh0000/"、/"rlt_msg/":/"/"} "; jsonobject jsonobject = json.parseobject(res);文字列data = jsonobject.getString( "data"); jsonobject jsonobjects = json.parseobject(data); jsonarray ja = jsonobjects.getjsonarray( "rows"); 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"); SimpleDateFormat simpledateFormat = new simpledateFormat( "yyyy-mm-dd hh:mm:ss"); long lt = new long(op_time);日付date = new Date(lt); res = SimpleDateFormat.Format(date);文字列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对象提取值方法就是小编分享给大家的全部内容了、希望能给大家一个参考、也希望大家多多支持武林网。