Okay, Now I have an unordered list here:
The following source code is my solution. I think it's clear enough to show the principle to covert ul to json object. Good Luck :)
$(function() {
function buildJSON($li) {
var subObj = { "name": $li.contents().eq(0).text().trim() };
$li.children('ul').children().each(function() {
if (!subObj.children) { subObj.children = []; }
subObj.children.push(buildJSON($(this)));
});
return subObj;
}
var obj = buildJSON($("#ul-data").children());
$('body').append('').find('pre').append(JSON.stringify(obj, null, 2));
});