【问题标题】:Can anyone please tell how to iterate and use a json array of maps in jsp?谁能告诉如何在jsp中迭代和使用一个json映射数组?
【发布时间】:2023-03-07 01:35:01
【问题描述】:

我的 javascript 中有我的 json 数据(地图数组),如下所示:

[
{"HOURLY":"$309.75","Airport Fee":"$15.00","STC":"$52.66","Gratuity":"$61.95","Fuel Surcharge":"$5.00"},
{"HOURLY":"$309.75","Airport Fee":"$15.00","STC":"$52.66","Gratuity":"$61.95","Fuel Surcharge":"$5.00"}
]

我想使用 object.valuemap.getValueBykey 机制在我的 jsp 中使用其中一个映射的值,就像我们使用从 java 传递到 jsp 的模型对象一样。

【问题讨论】:

    标签: javascript jquery json jsp jstl


    【解决方案1】:

    看到你有一个对象数组,首先把它当作一个数组来对待。所以,

    prices = [
      {"HOURLY":"$309.75","Airport Fee":"$15.00","STC":"$52.66","Gratuity":"$61.95","Fuel Surcharge":"$5.00"},
      {"HOURLY":"$329.75","Airport Fee":"$15.00","STC":"$52.66","Gratuity":"$61.95","Fuel Surcharge":"$5.00"}
    ];
    
    console.log(prices[0].HOURLY); // will output "$309.75", value found in the first object
    console.log(prices[1].HOURLY); // will output "$329.75", value found in the second object
    
    // If you want to get all values of that one property in all objects in the array, you can iterate like this:
    for(var i =0;i <prices.length;i++){
      console.log( prices[i].HOURLY);
    }
    
    // If you want to get all values for each property in a specific object, for example the first one in the array, you can iterate like this :
    for(key in prices[0]){
      console.log("'" +key + "' = " + prices[0][key]);
    }
    

    这就是它在 JavaScript 中的实现方式。 但是,我看到您在询问有关 JSP 的问题。也许您正在寻找这样的示例: javax.servlet.ServletException: javax.servlet.jsp.JspTagException: Don't know how to iterate over supplied "items" in <forEach>

    【讨论】:

      猜你喜欢
      • 2015-05-26
      • 2018-01-21
      • 1970-01-01
      • 1970-01-01
      • 2019-08-04
      • 1970-01-01
      • 2021-09-08
      • 2012-11-14
      • 1970-01-01
      相关资源
      最近更新 更多