Help coderanch get a
new server
by contributing to the fundraiser
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

How to print java Map name/value pair through JSON object in JS

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi
I am using struts2 framework and from my js file I am invoking my action class through AJAX call.In the success part of ajax I am getting a JSON object of java map like below


where typeModel is a object of DeviceTypeModel class and DeviceTypeModel class is having a java Map <String,String> class variable.
My question is in the java script part after getting the json object, how can I access this map key/value pair using JSON so that in the jsp page I can print the name/value pair
for the whole map object.

Please help me...............
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you asking how to create DOM elements for each key/value pair in the JavaScript object? Which part of that specifically given you a problem, iterating over an object's properties, or creating the DOM elements?

Please don't post the Struts-specific part in the HTML/JS forum--it's completely irrelevant to what you're trying to do. How the JSON is retrieved is totally irrelevant--you're basically asking how to iterate this:Right?
 
Kuts Aryan
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks for your reply and you are correct.I want to know about the iteration of JSON object.Right now I am doing the iteration like below


It is working but the order of displaying the element is not proper.If my JSON object contains

var foo = { "A":"a","B":"b","C":"c","D":"d"};
It is sometimes printing the oder like
D:d
A:a
B:b
C:c
like this.......Is there any way to display the order properly ?
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Object properties are not ordered. So there is no such thing as "proper order".

If you want ordered, use an array.
 
reply
    Bookmark Topic Watch Topic
  • New Topic