我如何使用 JSTL 打印 json 数据
How do i print json data using JSTL
我想使用 JSTL 标签显示 JSON。
但发生错误
如何打印 JsonData1、JsonData2?
错误信息
javax.el.PropertyNotFoundException: Property 'name' not found on type java.util.HashMap$Node
javax.el.PropertyNotFoundException: Property 'rating' not found on type java.util.HashMap$Node
javax.el.PropertyNotFoundException: Property 'reviews' not found on type java.util.HashMap$Node
jsonData1
{
"formatted_address": "369 Sang-doro, Sangdo-dong, Dongjak-gu, Seoul, South Korea",
"name": "Soongsil University",
"rating": 4.5,
"geometry": {
"viewport": {
"southwest": {
"lng": 126.9561097701073,
"lat": 37.49496127010728
},
"northeast": {
"lng": 126.9588094298927,
"lat": 37.49766092989272
}
},
"location": {
"lng": 126.9574596,
"lat": 37.4963111
}
},
"photos": [
{
"photo_reference": "CmRaAAAAyUDBODCqYW_EVYKccDbRt9oXRAsTwpQOVsqsQfGnF8ECPUV_iMrhQnqSvewvKVSPYyJ9Z4NzmhnxZAuLaUVrG349fvz8hOIByjDQwMyoJ_fjkuZKRRZgVny3_RE-dV_9EhAk2TP_bhnDDDzviwB73HWUGhRIfzevRbEdJhBJu-i86iYUFgOe1g",
"width": 3120,
"html_attributions": [
"<a href=\"https://maps.google.com/maps/contrib/114600581232781423634\">박영식</a>"
],
"height": 4160
}
],
"place_id": "ChIJzUGSjdahfDURxZ5P_MX-EdM"
}
jsonData2
{
"reviews": [
{
"author_name": "Benjamin Reim",
"profile_photo_url": "https://lh6.ggpht.com/-KuFCnWa56yY/AAAAAAAAAAI/AAAAAAAAAAA/624c90s3fuk/s128-c0x00000000-cc-rp-mo-ba3/photo.jpg",
"author_url": "https://www.google.com/maps/contrib/110076368758079993748/reviews",
"rating": 5,
"language": "en",
"text": "Awesome university. Great variety of student clubs, nice atmosphere among the students, modern facilities and a very beautiful campus site.",
"time": 1477717288,
"relative_time_description": "3 years ago"
},
{
"author_name": "Kim Jiho",
"profile_photo_url": "https://lh6.ggpht.com/-gF8ueHov1fI/AAAAAAAAAAI/AAAAAAAAAAA/PpaMqjyEmtI/s128-c0x00000000-cc-rp-mo/photo.jpg",
"author_url": "https://www.google.com/maps/contrib/111735439867054263549/reviews",
"rating": 5,
"language": "en",
"text": "Here is best places for training parkour. ",
"time": 1360156533,
"relative_time_description": "6 years ago"
},
{
"author_name": "Dajun Ding",
"profile_photo_url": "https://lh5.ggpht.com/-JiebyN0jymE/AAAAAAAAAAI/AAAAAAAAAAA/Thp1FIdOh6g/s128-c0x00000000-cc-rp-mo/photo.jpg",
"author_url": "https://www.google.com/maps/contrib/113953052797905419575/reviews",
"rating": 5,
"language": "en",
"text": "The academic environment on campus is admirable.",
"time": 1364281678,
"relative_time_description": "6 years ago"
},
{
"author_name": "Gatherlight Young",
"profile_photo_url": "https://lh4.ggpht.com/-yNs4iJb-Jz4/AAAAAAAAAAI/AAAAAAAAAAA/doyiFBNF6g8/s128-c0x00000000-cc-rp-mo/photo.jpg",
"author_url": "https://www.google.com/maps/contrib/114484921735380034491/reviews",
"rating": 5,
"language": "en",
"text": "Nice University 95",
"time": 1480327371,
"relative_time_description": "3 years ago"
},
{
"author_name": "Young Ho Kim",
"profile_photo_url": "https://lh3.ggpht.com/-tz82Qksuyt4/AAAAAAAAAAI/AAAAAAAAAAA/RggaENmSQn0/s128-c0x00000000-cc-rp-mo-ba4/photo.jpg",
"author_url": "https://www.google.com/maps/contrib/114527872121517025812/reviews",
"rating": 4,
"language": "en",
"text": "Good buildings ",
"time": 1500330691,
"relative_time_description": "2 years ago"
}
],
"name": "Soongsil University",
"rating": 4.5,
"formatted_phone_number": "02-820-0114"
}
JSP 文件正文
<body>
<c:forEach items="${jsonData1}" var="list">
${list.name}
${list.rating}
</c:forEach>
<c:forEach items="${jsonData2}" var="list">
${list.reviews}
</c:forEach>
</body>
jsonData1
好像是HashMap
。
您不需要 forEach
:您为什么要迭代地图的条目?。您想要访问与 HashMap 中的键关联的值。 Java 代码 jsonData1.get("name")
的等效项也是如此。因此,使用 JSP EL:
${jsonData1['name']}
我想使用 JSTL 标签显示 JSON。
但发生错误
如何打印 JsonData1、JsonData2?
错误信息
javax.el.PropertyNotFoundException: Property 'name' not found on type java.util.HashMap$Node javax.el.PropertyNotFoundException: Property 'rating' not found on type java.util.HashMap$Node javax.el.PropertyNotFoundException: Property 'reviews' not found on type java.util.HashMap$Node
jsonData1
{
"formatted_address": "369 Sang-doro, Sangdo-dong, Dongjak-gu, Seoul, South Korea",
"name": "Soongsil University",
"rating": 4.5,
"geometry": {
"viewport": {
"southwest": {
"lng": 126.9561097701073,
"lat": 37.49496127010728
},
"northeast": {
"lng": 126.9588094298927,
"lat": 37.49766092989272
}
},
"location": {
"lng": 126.9574596,
"lat": 37.4963111
}
},
"photos": [
{
"photo_reference": "CmRaAAAAyUDBODCqYW_EVYKccDbRt9oXRAsTwpQOVsqsQfGnF8ECPUV_iMrhQnqSvewvKVSPYyJ9Z4NzmhnxZAuLaUVrG349fvz8hOIByjDQwMyoJ_fjkuZKRRZgVny3_RE-dV_9EhAk2TP_bhnDDDzviwB73HWUGhRIfzevRbEdJhBJu-i86iYUFgOe1g",
"width": 3120,
"html_attributions": [
"<a href=\"https://maps.google.com/maps/contrib/114600581232781423634\">박영식</a>"
],
"height": 4160
}
],
"place_id": "ChIJzUGSjdahfDURxZ5P_MX-EdM"
}
jsonData2
{
"reviews": [
{
"author_name": "Benjamin Reim",
"profile_photo_url": "https://lh6.ggpht.com/-KuFCnWa56yY/AAAAAAAAAAI/AAAAAAAAAAA/624c90s3fuk/s128-c0x00000000-cc-rp-mo-ba3/photo.jpg",
"author_url": "https://www.google.com/maps/contrib/110076368758079993748/reviews",
"rating": 5,
"language": "en",
"text": "Awesome university. Great variety of student clubs, nice atmosphere among the students, modern facilities and a very beautiful campus site.",
"time": 1477717288,
"relative_time_description": "3 years ago"
},
{
"author_name": "Kim Jiho",
"profile_photo_url": "https://lh6.ggpht.com/-gF8ueHov1fI/AAAAAAAAAAI/AAAAAAAAAAA/PpaMqjyEmtI/s128-c0x00000000-cc-rp-mo/photo.jpg",
"author_url": "https://www.google.com/maps/contrib/111735439867054263549/reviews",
"rating": 5,
"language": "en",
"text": "Here is best places for training parkour. ",
"time": 1360156533,
"relative_time_description": "6 years ago"
},
{
"author_name": "Dajun Ding",
"profile_photo_url": "https://lh5.ggpht.com/-JiebyN0jymE/AAAAAAAAAAI/AAAAAAAAAAA/Thp1FIdOh6g/s128-c0x00000000-cc-rp-mo/photo.jpg",
"author_url": "https://www.google.com/maps/contrib/113953052797905419575/reviews",
"rating": 5,
"language": "en",
"text": "The academic environment on campus is admirable.",
"time": 1364281678,
"relative_time_description": "6 years ago"
},
{
"author_name": "Gatherlight Young",
"profile_photo_url": "https://lh4.ggpht.com/-yNs4iJb-Jz4/AAAAAAAAAAI/AAAAAAAAAAA/doyiFBNF6g8/s128-c0x00000000-cc-rp-mo/photo.jpg",
"author_url": "https://www.google.com/maps/contrib/114484921735380034491/reviews",
"rating": 5,
"language": "en",
"text": "Nice University 95",
"time": 1480327371,
"relative_time_description": "3 years ago"
},
{
"author_name": "Young Ho Kim",
"profile_photo_url": "https://lh3.ggpht.com/-tz82Qksuyt4/AAAAAAAAAAI/AAAAAAAAAAA/RggaENmSQn0/s128-c0x00000000-cc-rp-mo-ba4/photo.jpg",
"author_url": "https://www.google.com/maps/contrib/114527872121517025812/reviews",
"rating": 4,
"language": "en",
"text": "Good buildings ",
"time": 1500330691,
"relative_time_description": "2 years ago"
}
],
"name": "Soongsil University",
"rating": 4.5,
"formatted_phone_number": "02-820-0114"
}
JSP 文件正文
<body>
<c:forEach items="${jsonData1}" var="list">
${list.name}
${list.rating}
</c:forEach>
<c:forEach items="${jsonData2}" var="list">
${list.reviews}
</c:forEach>
</body>
jsonData1
好像是HashMap
。
您不需要 forEach
:您为什么要迭代地图的条目?。您想要访问与 HashMap 中的键关联的值。 Java 代码 jsonData1.get("name")
的等效项也是如此。因此,使用 JSP EL:
${jsonData1['name']}