tags:

views:

110

answers:

3

Hi

I have two strings Listing1(one in html format)

<ul>
    <li id="1"></li>
    <li id="2"></li>
    <li id="3"></li>
    <li id="4"></li>
    <li id="5"></li>
    <li id="6"></li>
</ul>

Listing2(one in json format)

{1:"r1",4:"r2"}

I need to fill the html string with the json data provided in listing 2 based on json key and id in html. Can any one help me to solve this issue.

Thanks Jineesh

A: 

can you show the HTML format please?

jeff porter
A: 

use regular expressions to get the name/values from the JSON String and put them in the HTML. You can use the split() and replaceAll() methods of the String class to do this.

EJB
+1  A: 

JS/JQuery part pseudocode

$(document).ready(function() {
     //iterate over the json data; pick up the id and value.
     for(key in jsonData)
     {
        $('#key').val(jsonData[key]);
     }
});

Using JQuery is not necessary though.

That's the easier way to solve your problem. Why you need to handle this in Java?

Ketan Khairnar