Lets say I have an unordered nested list:
<ul>
<li>Item a1</li>
<li>Item a2</li>
<li>Item a3</li>
<ul>
<li>Item b1</li>
<li>Item b2</li>
<li>Item b3</li>
<ul>
<li>Item c1</li>
<li>Item c2</li>
<li>Item c3</li>
</ul>
<li>Item b4</li>
</ul>
<li>Item a4</li>
</ul>
I need to traverse it and save it in a two dimensional array (ultimately I’m just trying to convert it into a JSON entity) I am allowed to use both Jquery AND/OR Javascript. How should I proceed?
Thanks
I’m not sure exactly what you want the resulting data structure to look like, but this (which uses some jQuery):
… would produce this structure
It could be fairly easily tweaked to alter details of the resulting structure if needed.
Please note that this is a javascript object. If you actually need a JSON object, then you just need to convert it using
var jsonResult = JSON.stringify( result );