我如何使用JSTL打印JSON数据

时间:2019-12-14 14:07:07

标签: json jsp jstl

我想使用JSTL标签显示JSON。
但发生错误
如何打印JsonData1,JsonData2?

错误消息

  

javax.el.PropertyNotFoundException:在类型java.util.HashMap $ Node上找不到属性“名称”   javax.el.PropertyNotFoundException:在类型java.util.HashMap $ Node上找不到属性“评级”   javax.el.PropertyNotFoundException:在类型java.util.HashMap $ Node

上找不到属性“ reviews”

jsonData1

(secs % 60 < 10 ? "0" : "")

jsonData2

{
  "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"
}

JSP文件的正文

{
  "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"
}

1 个答案:

答案 0 :(得分:0)

jsonData1似乎是HashMap

您不希望使用forEach:为什么要遍历地图条目?您要访问与HashMap中的键关联的值。 Java代码jsonData1.get("name")的等效项也是如此。因此,使用JSP EL:

${jsonData1['name']}