user890263
user890263

Reputation: 159

jQuery : How can I iterate over Java HashMap<Long,String> into Javascript?

I am returning HashMap<Long,String> from server on one of the Ajax calls. How can I iterate over the it to extract key,value pair?

Thank you

Upvotes: 0

Views: 2058

Answers (1)

Aaron Digulla
Aaron Digulla

Reputation: 328724

Return it as JSON object:

{1:"String",5:"Foo"}

On the client, you can then access the elements then using data[1] and data[5]. While it looks like an array access, JavaScript will do the right thing (Kudos to Felix Kling for pointing that out).

Upvotes: 1

Related Questions