N
N
Nikita Konovalov2017-02-05 11:34:05
JavaScript
Nikita Konovalov, 2017-02-05 11:34:05

How to create a list of links in html from json?

Hello everyone
It is necessary to get a bulleted list from json, each element of which is a link.
Now the json file looks something like this:

{
  "LinkList": [
    {
      "Name": "Fisrt",
      "Link": "/first.html",
    },
    {
      "Name": "Second",
      "Link": "/second.html",
    }
  ]
}

Thanks in advance for advice and solutions :-)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
I
Ivan, 2017-02-05
@LiguidCool

You can use a template engine. For example HandlebarsJS.

A
Alexey Povolnov, 2017-02-06
@KNLNT

let's say your json is msg variable
then

msg = $.parseJSON(msg);
spisok = '<ul>';

for ( i=0; i<=msg.length(); i++ ) {
    spisok = spisok+'<li><a href="'+msg[i]+'">Ссылка №'+i+'</a></li>';
}

spisok = spisok+'</ul>';
$('body').html(spisok);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question