如何将 json url 显示到 html

How to display json url to html?

本文关键字:显示 html url json      更新时间:2023-09-26

我在jquery中很慢,我试图研究如何将json文件从url显示到html,但似乎我没有收到代码。我只想在这里显示这个 json 数据:http://api.paperstreetjobs.com/exam/show/getProblems

我想向我的 html 显示数组中的每个问题和难度值。

我的 json:

[
[
   {
    "id":26,"question":"What html element will the following CSS code selects?'r'n'r'nli:not(#foo) > fieldset > div > span > input[type='radio'], 'r'nli:not(#foo) > fieldset > div > span > input[type='checkbox']",
    "note":"",
    "difficulty":"easy",
    "language":"css"
   }
],
[
   {
     "id":18,"question":"Try to figure out what is wrong with the codes below. Explain your answer'r'n'r'n",
     "note":"",
     "difficulty":"average",
     "language":"php"
   }
],
[
   {
     "id":112,
     "question":"Assuming there is a sample.json file inside your directory. That contains'r'n{'"1'":{'"id'":1,'"clicks'":100,'"stars'":5},'"2'":{'"id'":2,'"clicks'":120,'"stars'":2},'"3'":{'"id'":3,'"clicks'":60,'"stars'":3}}'r'n 'r'nGet the value of the json file'r'nSort the values according to its 'u201cstars'u201d descending and 'u201cclicks'u201d descending.'r'nReplace the sample.json content to the sorted value assuming that the file is writable.'r'nAssuming that the values changes once a day, your code should adopt to the values of 'u201cclicks'u201d and 'u201cstars'u201d",
     "note":"",
     "difficulty":"hard",
     "language":"php"
   }
]
]

请帮助我并指导我。 提前感谢!

这很简单。

$.get( "http://api.paperstreetjobs.com/exam/show/getProblems", function( data ) {
  $( ".result" ).html( data );
  alert( "Load was performed." );
});

您可以使用@Deep代码来呈现它。

最好

叶戈尔

这是完整 ajax 查询的回调代码:

var
    itemsBox = $('#items-box'),
    i;
for (i = 0; i < yourJSON[0].length; i++) {
    itemsBox.append(''
        + '<div>id: '         + yourJSON[i][0].id         + '</div>'
        + '<div>question: '   + yourJSON[i][0].question   + '</div>'
        + '<div>note: '       + yourJSON[i][0].note       + '</div>'
        + '<div>difficulty: ' + yourJSON[i][0].difficulty + '</div>'
        + '<div>language: '   + yourJSON[i][0].language   + '</div>'
    );
}