邢臺易優(yōu)網(wǎng)絡(luò)科技有限公司seo網(wǎng)站排名的軟件
該方法接收一個(gè)JSON字符串參數(shù)phoneNum 內(nèi)容: {"phone":"13712312312"} 然后解析參數(shù)中的手機(jī)號,作為data去調(diào)用URL接口,接收接口返回的復(fù)合JSON并解析,拿到想要的數(shù)據(jù)public String queryUserResumeURLInfo(String phoneNum) {System.out.println("this is phoneNum: ======"+phoneNum);if(phoneNum.length() == 0){log.info("手機(jī)號為空!" );return null;}// 請求地址String url = "訪問認(rèn)證的URL";HttpHeaders headers = new HttpHeaders();String mediaType = MediaType.APPLICATION_JSON_VALUE;headers.setContentType(MediaType.parseMediaType(mediaType));headers.set("Accept", mediaType); // headers.set("Basic Auth", "uVJowCwUE08z2Hfw0aLXTZvZo66C19Rk");headers.set("Authorization", "Basic " + Base64.getUrlEncoder().encodeToString(("用戶名" + ":" + "密碼").getBytes()));Map<String, Object> map = new HashMap<>();//傳遞參數(shù),這里解析了傳進(jìn)來的JSON類型的手機(jī)號,并作為參數(shù)傳給調(diào)用的接口map.put("phone", phoneNum.substring(phoneNum.indexOf(":")+2,phoneNum.lastIndexOf("}")-1));JSONObject json = new JSONObject(map);// System.out.println("this is json: ======"+json.toString());HttpMethod method = HttpMethod.POST;try {ResponseEntity<JSONObject> result = RestUtil.request(url, method, headers, null, json, JSONObject.class);if (result != null && result.getBody() != null) {log.info("返回結(jié)果:{}" ,result.getBody().toJSONString());JSONObject jsonObject = JSONObject.parseObject(result.getBody().toString());String resumeDataInfo =jsonObject.getJSONArray("data").getJSONObject(0).getJSONObject("basicInfo").getString("ehrCandidateExternalLink"); // System.out.println("this is data:-------"+resumeDataInfo);return resumeDataInfo;} else {log.warn("查詢失敗,url={}",url);}}catch (Exception e){log.error("查詢發(fā)生異常,url={}",url,e);}return null;}
其中fastJSON解析復(fù)雜JSON文本
java中fastJSON解析復(fù)合-CSDN博客