2

I really need your help, i cant get all data from this API: http://datahub.virk.dk/api/2/rest/package/smiley-kontrolrapporter

this is my code

<div class="mypanel"></div>

<script>
$.getJSON('http://datahub.virk.dk/api/2/rest/package/smiley-kontrolrapporter', function(data) {

    var text = `<h2>${data.license_title}</h2><br>
                <h2>${data.url}</h2><br>
                <h2>${data.url}</h2><br>
                <h2>${data.url}</h2><br>
                ${data.resources.description}`


    $(".mypanel").html(text);
});
</script>

please help me. thank you.

1
  • could you please see me the example to do that? i cant follow the link, i dont know how to read.. Commented Feb 15, 2018 at 14:01

1 Answer 1

3

The url is empty in that link. You most likely mean the url in the resources array items. But since it is an array you need to iterate or target the specific index you want. The same goes for the description. It is not part of the resources, it is part of each item in the resources.

Something like

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="mypanel"></div>

<script>
  $.getJSON('http://datahub.virk.dk/api/2/rest/package/smiley-kontrolrapporter', function(data) {

    var resources = data.resources.map(resource => `<a href="${resource.url}">${resource.description}</a><br>`),
        text = `<h2>${data.license_title}</h2><br>
               ${resources.join('')}`;

    $(".mypanel").html(text);
  });
</script>

Sign up to request clarification or add additional context in comments.

7 Comments

thank you, so it will be okay if i follow your code to the rest?
` <i>Tags: ${data.tags}</i> <p><b>Organization description:</b> ${data.organization.description}</p> <p><b>Organization title:</b> ${data.organization.title}</p> <p><b>Organization created:</b> ${data.organization.created}</p> <p><b>Organization Status:</b> ${data.organization.approval_status}</p> <p><b>Name:</b> ${data.name}</p> <p><b>Notes:</b> ${data.notes_rendered} ` it looks like this?
Thanks, how about the last part sir? in ' extras ', i dont know how to do that.. and also i got '[HTML_REMOVED]'. how to fix that? this is my working links.. smiley.design4web.dk/api.html
@JorhendzStudios extras is a normal object so you access its properties with data.extras.area_id etc. ABout the HTML_REMOVED that is what is returned in the JSON so nothing to do about it unless the API can provide this somehow.
@JorhendzStudios when using the . notation you cannot have - in the property names. You should use ${data.extras['contact-name']} and ${data.extras['theme-primary']}
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.