参数列表:
categoryId
categoryName
gmt_create
id
idPushTop
privateLevel
title
url
数据格式:
{"blackboard_list":[
{"categoryId":"bc294bfd8d216e9c28fe708ebe70f754","categoryName":"aaa","gmt_create":"2023-03-24 22:51:55","id":"0559dd7fc77b1f3ffe87d6388b7027e7","isPushTop":1,"privateLevel":20,"title":"测试-3","url":"https:\/\/app.dingtalk.com\/blackboard\/h5\/listNotice?showmenu=true&dd_progress=false&dd_share=true&ddfrom=&logkey=&corpid=ding73cb94ec65ce399324f2f5cc6abecb85#\/detail\/0559dd7fc77b1f3ffe87d6388b7027e7"}
,{"categoryId":"bc294bfd8d216e9c28fe708ebe70f754","categoryName":"aaa","gmt_create":"2023-03-24 22:48:54","id":"61f24038dd1ce5837b9025ac2bc318b2","isPushTop":1,"privateLevel":0,"title":"demo-tree","url":"https:\/\/app.dingtalk.com\/blackboard\/h5\/listNotice?showmenu=true&dd_progress=false&dd_share=true&ddfrom=&logkey=&corpid=ding73cb94ec65ce399324f2f5cc6abecb85#\/detail\/61f24038dd1ce5837b9025ac2bc318b2"}
,{"categoryId":"bc294bfd8d216e9c28fe708ebe70f754","categoryName":"aaa","gmt_create":"2023-03-24 22:46:51","id":"c75cd501225257a7ed301f6cfc26b374","isPushTop":1,"privateLevel":0,"title":"test","url":"https:\/\/app.dingtalk.com\/blackboard\/h5\/listNotice?showmenu=true&dd_progress=false&dd_share=true&ddfrom=&logkey=&corpid=ding73cb94ec65ce399324f2f5cc6abecb85#\/detail\/c75cd501225257a7ed301f6cfc26b374"}
,{"categoryId":"bc294bfd8d216e9c28fe708ebe70f754","categoryName":"aaa","gmt_create":"2023-03-24 17:33:32","id":"43276a3708353040d56fe3895d44ba28","isPushTop":1,"privateLevel":0,"title":"测试-one","url":"https:\/\/app.dingtalk.com\/blackboard\/h5\/listNotice?showmenu=true&dd_progress=false&dd_share=true&ddfrom=&logkey=&corpid=ding73cb94ec65ce399324f2f5cc6abecb85#\/detail\/43276a3708353040d56fe3895d44ba28"}
,{"categoryId":"bc294bfd8d216e9c28fe708ebe70f754","categoryName":"aaa","gmt_create":"2023-03-29 16:32:11","id":"36a5dee27faa3fbc26995ad0710a28c2","isPushTop":0,"privateLevel":0,"title":"test—1","url":"https:\/\/app.dingtalk.com\/blackboard\/h5\/listNotice?showmenu=true&dd_progress=false&dd_share=true&ddfrom=&logkey=&corpid=ding73cb94ec65ce399324f2f5cc6abecb85#\/detail\/36a5dee27faa3fbc26995ad0710a28c2"}
,{"gmt_create":"2023-03-24 13:59:00","id":"c6aa2c69fb3624c8d54e49635087d155","isPushTop":0,"privateLevel":0,"title":"测试1","url":"https:\/\/app.dingtalk.com\/blackboard\/h5\/listNotice?showmenu=true&dd_progress=false&dd_share=true&ddfrom=&logkey=&corpid=ding73cb94ec65ce399324f2f5cc6abecb85#\/detail\/c6aa2c69fb3624c8d54e49635087d155"}
],
"errcode":0,
"errmsg":"ok",
"request_id":"16lsip7rz1ael"}
基于new Bing 的回答:
假设输入的数据是一个JSON格式的字符串,可以通过JSON库将其解析成一个对象。然后可以遍历解析后的对象,获取每个元素的属性值。
示例代码:
import org.json.JSONArray;
import org.json.JSONObject;
public class BlackboardParser {
public static void main(String[] args) {
String jsonStr = "{\"blackboard_list\":[{\"categoryId\":\"bc294bfd8d216e9c28fe708ebe70f754\",\"categoryName\":\"aaa\",\"gmt_create\":\"2023-03-24 22:51:55\",\"id\":\"0559dd7fc77b1f3ffe87d6388b7027e7\",\"isPushTop\":1,\"privateLevel\":20,\"title\":\"测试-3\",\"url\":\"https:\\/\\/app.dingtalk.com\\/blackboard\\/h5\\/listNotice?showmenu=true&dd_progress=false&dd_share=true&ddfrom=&logkey=&corpid=ding73cb94ec65ce399324f2f5cc6abecb85#\\/detail\\/0559dd7fc77b1f3ffe87d6388b7027e7\"},{\"categoryId\":\"bc294bfd8d216e9c28fe708ebe70f754\",\"categoryName\":\"aaa\",\"gmt_create\":\"2023-03-24 22:48:54\",\"id\":\"61f24038dd1ce5837b9025ac2bc318b2\",\"isPushTop\":1,\"privateLevel\":0,\"title\":\"demo-tree\",\"url\":\"https:\\/\\/app.dingtalk.com\\/blackboard\\/h5\\/listNotice?showmenu=true&dd_progress=false&dd_share=true&ddfrom=&logkey=&corpid=ding73cb94ec65ce399324f2f5cc6abecb85#\\/detail\\/61f24038dd1ce5837b9025ac2bc318b2\"}],\"errcode\":0,\"errmsg\":\"ok\",\"request_id\":\"16lsip7rz1ael\"}";
JSONObject jsonObj = new JSONObject(jsonStr);
JSONArray blackboardList = jsonObj.getJSONArray("blackboard_list");
for (int i = 0; i < blackboardList.length(); i++) {
JSONObject item = blackboardList.getJSONObject(i);
String categoryId = item.getString("categoryId");
String categoryName = item.getString("categoryName");
String gmtCreate = item.getString("gmt_create");
String id = item.getString("id");
int isPushTop = item.getInt("isPushTop");
int privateLevel = item.getInt("privateLevel");
String title = item.getString("title");
String url = item.getString("url");
// 输出每个元素的属性值
System.out.println("categoryId: " + categoryId);
System.out.println("categoryName: " + categoryName);
System.out.println("gmt_create: " + gmtCreate);
System.out.println("id: " + id);
System.out.println("isPushTop: " + isPushTop);
System.out.println("privateLevel: " + privateLevel);
System.out.println("title: " + title);
System.out.println("url: " + url);
}
}
}
该回答引用ChatGPTpython
import json
# JSON 数据
json_str = '{"blackboard_list":[\
{"categoryId":"bc294bfd8d216e9c28fe708ebe70f754","categoryName":"aaa","gmt_create":"2023-03-24 22:51:55","id":"0559dd7fc77b1f3ffe87d6388b7027e7","isPushTop":1,"privateLevel":20,"title":"测试-3","url":"https:\\/\\/app.dingtalk.com\\/blackboard\\/h5\\/listNotice?showmenu=true&dd_progress=false&dd_share=true&ddfrom=&logkey=&corpid=ding73cb94ec65ce399324f2f5cc6abecb85#\\/detail\\/0559dd7fc77b1f3ffe87d6388b7027e7"},\
{"categoryId":"bc294bfd8d216e9c28fe708ebe70f754","categoryName":"aaa","gmt_create":"2023-03-24 22:48:54","id":"61f24038dd1ce5837b9025ac2bc318b2","isPushTop":1,"privateLevel":0,"title":"demo-tree","url":"https:\\/\\/app.dingtalk.com\\/blackboard\\/h5\\/listNotice?showmenu=true&dd_progress=false&dd_share=true&ddfrom=&logkey=&corpid=ding73cb94ec65ce399324f2f5cc6abecb85#\\/detail\\/61f24038dd1ce5837b9025ac2bc318b2"},\
{"categoryId":"bc294bfd8d216e9c28fe708ebe70f754","categoryName":"aaa","gmt_create":"2023-03-24 22:46:51","id":"c75cd501225257a7ed301f6cfc26b374","isPushTop":1,"privateLevel":0,"title":"test","url":"https:\\/\\/app.dingtalk.com\\/blackboard\\/h5\\/listNotice?showmenu=true&dd_progress=false&dd_share=true&ddfrom=&logkey=&corpid=ding73cb94ec65ce399324f2f5cc6abecb85#\\/detail\\/c75cd501225257a7ed301f6cfc26b374"},\
{"categoryId":"bc294bfd8d216e9c28fe708ebe70f754","categoryName":"aaa","gmt_create":"2023-03-24 17:33:32","id":"43276a3708353040d56fe3895d44ba28","isPushTop":1,"privateLevel":0,"title":"测试-one","url":"https:\\/\\/app.dingtalk.com\\/blackboard\\/h5\\/listNotice?showmenu=true&dd_progress=false&dd_share=true&ddfrom=&logkey=&corpid=ding73cb94ec65ce399324f2f5cc6abecb85#\\/detail\\/43276a3708353040d56fe3895d44ba28"},\
{"categoryId":"bc294bfd8d216e9c28fe708ebe70f754","categoryName":"aaa","gmt_create":"2023-03-29 16:32:11","id":"36a5dee27faa3fbc26995ad0710a28c2","isPushTop":0,"privateLevel":0,"title":"test—1","url":"https:\\/\\/app.dingtalk.com\\/blackboard\\/h5\\/listNotice?showmenu=true&dd_progress=false&dd_share=true&ddfrom=&logkey=&corpid=ding73cb94ec65ce399324f2f5cc6abecb85#\\/detail\\/36a5dee27faa3fbc26995ad0710a28c2"},\
{"gmt_create":"2023-03-24 13:59:00","id":"c6aa2c69fb3624c8d54e49635087d155","isPushTop":0,"privateLevel":0,"title":"测试1","url":"https:\\/\\/app.dingtalk.com\\/blackboard\\/h5\\/listNotice?showmenu=true&dd_progress=false&dd_share=true&ddfrom=&logkey=&corpid=ding73cb94ec65ce399324f2f5cc6abecb85#\\/detail\\/c6aa2c69fb3624c8d54e49635087d155"}],\
"errcode":0,"errmsg":"ok","request_id":"16lsip7rz1ael"}'
# 将 JSON 数据转换成 Python 字典
data = json.loads(json_str)
# 要查找的 ID
target_id = '0559dd7fc77b1f3ffe87d6388b7027e7'
# 遍历 blackboard_list 数组,查找指定 ID 对应的内容
for item in data['blackboard_list']:
url = item['url']
# 将 URL 分割成多个部分,取最后一部分作为 ID
id = url.split('/')[-1]
if id == target_id:
print(item)
break
{'categoryId': 'bc294bfd8d216e9c28fe708ebe70f754', 'categoryName': 'aaa', 'gmt_create': '2023-03-24 22:51:55', 'id': '0559dd7fc77b1f3ffe87d6388b7027e7', 'isPushTop': 1, 'privateLevel': 20, 'title': '测试-3', 'url': 'https://app.dingtalk.com/blackboard/h5/listNotice?showmenu=true&dd_progress=false&dd_share=true&ddfrom=&logkey=&corpid=ding73cb94ec65ce399324f2f5cc6abecb85#/detail/0559dd7fc77b1f3ffe87d6388b7027e7'}