将Json转换为ul和li

Roy*_*ysh -3 html javascript jquery json

我有一个看起来像这样的对象:

{
    "qA": [
        {
            "question": "How deep is the ocean",
            "answer": [
                "quite deep",
                "very deep",
                "no deep at all"
            ]
        },
        {
            "question": "How high is the sky",
            "answer": [
                "real high",
                "high enough",
                "not that high"
            ]
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

我想把它加载到ul问题是标题的地方ul,答案就是它li.我怎么做?

Ehs*_*jad 7

你可以用这样的jquery做:

$.each(data.qA, function (index, item) {
    //console.log(item);
    html += "<ul>" + item.question;

    $.each(item.answer, function (index1, item1) {
        html += "<li>" + item1 + "</li>";

    });
    html+="</ul>";
});
$("#container").append(html);
Run Code Online (Sandbox Code Playgroud)

FIDDLE DEMO