You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

47 lines
1.7 KiB

1 month ago
  1. package com.example;
  2. import okhttp3.*;
  3. import org.json.JSONArray;
  4. import org.json.JSONObject;
  5. import org.jsoup.Jsoup;
  6. import org.jsoup.nodes.Document;
  7. import java.io.IOException;
  8. import java.util.HashMap;
  9. import java.util.Map;
  10. public class jsonGetOk {
  11. public static void main(String[] args) throws IOException {
  12. OkHttpClient client = new OkHttpClient().newBuilder()
  13. .build();
  14. MediaType mediaType = MediaType.parse("text/plain");
  15. RequestBody body = RequestBody.create(mediaType, "");
  16. Request request = new Request.Builder()
  17. .url("https://www.dsscu.gov.mo/api/common/page_detail?PostType=page&EntityId=6654829e-8163-b801-0096-c02e09d690d1")
  18. .get()
  19. .build();
  20. Response response = client.newCall(request).execute();
  21. String responseBody = response.body().string();
  22. // 解析 JSON
  23. JSONObject jsonObject = new JSONObject(responseBody);
  24. JSONObject data = jsonObject.getJSONObject("data");
  25. String postTime = data.getString("onlineAt");
  26. JSONObject metas = data.getJSONObject("metas");
  27. String title = metas.getString("name");
  28. String summary = metas.getString("summary");
  29. Document parse = Jsoup.parse(summary);
  30. String content = parse.text();
  31. String forwardcontent = responseBody;
  32. String fileList = metas.getString("biddersFile");
  33. fileList = fileList+"###"+"pdf";
  34. Map<String,Object> map = new HashMap<>();
  35. map.put("postTime",postTime);
  36. map.put("title",title);
  37. map.put("content",content);
  38. map.put("forwardcontent",forwardcontent);
  39. map.put("fileList",fileList);
  40. System.out.println(map);
  41. }
  42. }