3
How do I create a JSON with several different names?
Equal: [{name: "john"}, {name: "peter"}]
Could someone give me an example?
I tried to do so, but why does he always return the last item twice? Like John in the first and then Peter twice?
$(".item-tbody .nome").each(function ()
{
obj.nome = $(this).parent().find('.nome').text();
arrayObj.push(obj);
nomeArray = JSON.stringify(arrayObj);
alert(nomeArray);
});
Will be
JSON.stringify('[{nome: "joão"}, {nome: "pedro"}]');
? https://jsfiddle.net/rwctqhu9/ . I don’t think there’s a better way to use jquery, simply use the native javascript function– Miguel
Yes. It comes from a single variable. Type the two comes from the name variable. How do I break the two that look the same in the above model?
– Felipe Michael da Fonseca
Isn’t that like the link I put on top? You want two jsons, one for each obj inside the array, that’s it?
– Miguel
Yes, like this one. Only John and Peter come from a single variable. How do I break it so it looks like the one you said above?
– Felipe Michael da Fonseca
I have the variable name, which comes: John and Peter.
– Felipe Michael da Fonseca
Want each name in a different variable? eg:
var name1 = 'joão'; var name2 = 'pedro';
– Miguel
I have the variable name, which comes: John and Peter right? It comes with these two names, but I want it to be broken and put like this: [{name: "john"}, {name: "peter"}]
– Felipe Michael da Fonseca
So https://jsfiddle.net/7vr9Lq3h/1/?
– Miguel
Dude I did so: obj.name = $(this). Parent(). find('. name'). text(); arrayObj.push(obj); nameArray = JSON.stringify(arrayObj); Alert(nameArray);
– Felipe Michael da Fonseca
He appears: [{"name":"john paul"}]. As I break them?
– Felipe Michael da Fonseca
Yes. It even worked, but he still cuts out the names: John, he puts: {"name":"J"},{"name":"the"} understand? var people = $(this). Parent(). find('. name'). text(); var Names = []; for(var i = 0; i < people.length; i++) { Names.push({name: people[i]}); } Alert(JSON.stringify(Names));
– Felipe Michael da Fonseca
Thank you. I will try looking in another forum.
– Felipe Michael da Fonseca