0
I’m stuck in a situation where I can’t turn the data blocks of the JSON file into HTML, nothing appears. Below I will put the codes for you to take a look
NOTE: If you can refer me to a legal JSON site I also need to know about filtering and adding posts, because each JSON block is a.
UPDATE OF THE PROBLEM
Guys I did below the updates of the resolution I had to show the JSON content in HTML, now just need to make the filter that has to be from data as popularity, Date and comment, I will follow the help of the friend and if I can do one more update here!!
HTML code (UPDATE)
<!DOCTYPE html>
<html lang="pt-br">
<head>
<link rel="stylesheet" href="css/style.css" />
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js"> </script>
<script type="text/javascript" src="dados.json"> </script>
</head>
<body>
<header><input id="filtro" type="text" placeholder="Busca Rápida"></header>
<main id= "dados" ></main>
<footer></footer>
</body>
</html>
JAVASCRIPT FILTER CODE (working)
<script>
$('#filtro').keyup(function () {
var yourtext = $(this).val();
if (yourtext.length > 0) {
var abc = $("section").filter(function () {
var str = $(this).text();
var re = new RegExp(yourtext, "i");
var result = re.test(str);
if (!result) {
return $(this);
}
}).hide();
} else {
$("section").show();
}
});
</script>
JSON(UPDATE)
window.onload=function(){
data = { person: [
{
author: 'Nobtaka Nukui',
title: 'Want people to use your product? Use it yourself',
url: 'http://www.medium.com',
category: 'Product Design',
comments: '4 coments',
created_at: '43 minutos atrás',
classcor: 'corUm',
foto: '<img src="img/ft-3.jpg" width="18" height="18" alt="Personagem1">',
upvotes: 11 },
{
author: "Danil Ishutin",
title: "Font Size Idea: px at Root, rem for Components, em for Text Elements",
url: "http://www.css-tricks.com",
category: "UX Theory",
comments: '7 coments',
created_at: '5 minutos atrás',
classcor: 'corDois',
foto: '<img src="img/ft-2.jpg" width="18" height="18" alt="Personagem2">',
upvotes: 9},
{
author: "Kenny Schrub",
title: "Some things cant be prototyped",
url: "http://www.mika.el",
category: "Opinion",
comments:'25 coments',
created_at: '7 minutos atrás',
classcor: 'corTres',
foto: '<img src="img/ft-2.jpg" width="18" height="18" alt="Personagem2">',
isOwner: true,
upvotes: 4
},
{
author: "Jacky Mao",
title: "How to prototype without any tools",
url: "http://www.jackymao.wix",
category: "Opinion",
comments: '0 coments',
classcor: 'corTres',
foto: '<img src="img/ft-1.jpg" width="18" height="18" alt="Personagem2">',
upvotes: 4
},
{
author: "Christopher Alesund",
title: "Case study: Redesigning the Folyo landing page",
url: "http://www.medium.com",
category: "Case Study",
comments: '0 coments',
classcor: 'corQuatro',
foto: '<img src="img/ft-1.jpg" width="18" height="18" alt="Personagem2">',
created_at: '7 hours ago',
upvotes: 3
},
{
author: "Pasha Biceps",
title: "Don't let bad process or structure kill great interfaces",
url: "http://www.medium.com",
category: 'Product Design',
comments: '0 coments',
classcor: 'corUm',
foto: '<img src="img/ft-3.jpg" width="18" height="18" alt="Personagem2">',
created_at: '2 days ago',
isOwner: true,
upvotes: 2
}
]};
data.person.forEach(function(p){
var post = "<section><span><a href='#'></a>"+p.upvotes+"</span><div><a href="+p.url+">"+p.url+"</a><h1>"+p.title+"</h1><nav><a href='#' id='bt-category' class="+ p.classcor +" title="+ p.category +">"+p.category+"</a><p>"+p.foto+"<a href='#' title="+p.author+">"+p.author+"</a>"+p.created_at+"<a href='#' class='coments'>"+p.comments+"</a></p></nav></div></section>";
document.querySelector('#dados').innerHTML += post;
});
}
Brother, what’s your question about Json? JSON is an array of objects. If you give a console.log in the date variable you will see it in its original state and you will be able to navigate it without difficulty.
– DiegoSantos
So this is why I’m learning JSON, and they gave me this to do, I researched everything when it’s place to see examples and the only one that worked was one with table, but when I try to reproduce the same with HTML does not work, sorry to nubisse!!
– user4451
imagine... Look, first understand the following. JSON is a format. That is, a way to store data. It could be for example XML. Knowing this, I will try to play an example of Json here as a response and you adapt your blz?
– DiegoSantos
blz, vlw even, because I’m lost heheh
– user4451
The problem is in assigning the value to variable
postRow
. You have single quotes where you should have double quotes, it doesn’t have the;
at the end. This all generates errors and so nothing is rendered.– Filipe Moraes
you say there in the link tags? pq was the only way Dreamweaver did not error
– user4451
I put an answer below, focusing on another way to consume JSON, which from what I saw is its difficulty. I think it’s easier to understand like this...
– DiegoSantos
on the line where you have
var postRow =
. Your problem is not only understanding how JSON works, but programming itself.– Filipe Moraes
@Filipemoraes If you mean space, is that I gave a enter there, but even without it it is not right
– user4451
I recently chose to use Vuejs and AXIOS, you can take a look at this answer to see how simple everything is https://answall.com/a/308311/5704
– Tony