import org.json.*; JSONObject json = new JSONObject(); json.put("name", "John"); json.put("age", 30); String jsonString = json.toString(); JSONArray jsonArray = new JSONArray(); JSONObject obj1 = new JSONObject(); obj1.put("name", "John"); obj1.put("age", 30); JSONObject obj2 = new JSONObject(); obj2.put("name", "Jane"); obj2.put("age", 28); jsonArray.put(obj1); jsonArray.put(obj2); String jsonString = jsonArray.toString(); import org.springframework.http.*; import org.springframework.web.client.*; RestTemplate restTemplate = new RestTemplate(); HttpHeaders headers = new HttpHeaders(); headers.setContentType(MediaType.APPLICATION_JSON); HttpEntity<String> entity = new HttpEntity<String>(jsonString, headers); ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class); String responseBody = response.getBody();


上一篇:
下一篇:
切换中文