0

I have my json data (array of map) in my javascript and it's like as below:

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

I want to use the values of one of the maps in my jsp using some object.value or map.getValueBykey mechanism as if just like we use a model object passed from java to jsp.

user2918640
  • 473
  • 1
  • 7
  • 25

1 Answers1

0

Seeing that you have an array of objects, treat it first like an array. So,

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]);
}

This is how it's done in JavaScript. I see you are asking about JSP however. Maybe an example like this is what you are looking for: javax.servlet.ServletException: javax.servlet.jsp.JspTagException: Don't know how to iterate over supplied "items" in <forEach>

Community
  • 1
  • 1
JohnRDOrazio
  • 1,358
  • 2
  • 15
  • 28