gpt4 book ai didi

java - 如何提取 key :value from html

转载 作者:行者123 更新时间:2023-12-01 10:03:10 25 4
gpt4 key购买 nike

我有以下从 servlet 发送到索引页的字符串数据。

{  "hits" : {"hits" : [ { "_source":{"ID":"123","Status":"false","Name":"ABC_123","Date":"2010-08-16T11:07:48"}    }, {      "_source":{"ID":"124","Status":"false","Name":"ABC_678","Date":"2010-08-16T12:00:12"}    }, {      "_source":{"ID":"125","Status":"true","Name":"FGH_122","Date":"2010-08-16T12:01:48"}    }, {      "_source":{"ID":"126","Status":"false","Name":"TYT_333","Date":"2010-08-16T12:06:48"}    }, {      "_source":{"ID":"127","Status":"false","Name":"CVF_230","Date":"2010-08-16T12:07:18"}    }, {      "_source":{"ID":"128","Status":"true","Name":"AWE_101","Date":"2010-08-16T12:03:48"}    }, {      "_source":{"ID":"129","Status":"true","Name":"WEC_299","Date":"2010-08-16T12:07:29"}    } ]  }}

我想解析数据并查看数组列表格式的数据,例如:

{ID:"123", "Name":"ABC_123"}
{ID:"124", "Name":"ABC_678"}

等等...

知道如何从客户端或服务器实现此目的吗?请指教..谢谢

最佳答案

创建一个新数组并向其中添加对象,然后将它们返回到 JSP。

JSONArray arr = new JSONArray();
for (int i = 0 ; i < hitsArray.length(); i++) {
JSONObject jObject = hitsArray.getJSONObject(i);
arr.put(jObject.get("_source"));
}

request.setAttribute("jsonObject", arr);
RequestDispatcher dispatcher = request.getRequestDispatcher("index.jsp");
dispatcher.forward(request, response);

关于java - 如何提取 key :value from html,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36660986/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com