0
I have to get the data that are being accumulated in the variable valore
and turn them into an array so you can catch them using HttpRequest
in an HTML page. How do I do this?
// Classe para chamar o JSON.
function json(){
var qtd;
var retorno;
// Resgatar valores.
json.prototype.resgatarValores = function(){
$('#resultado').html('Carregando dados...');
// Estrutura de resultado.
$.getJSON('/webpro/webadm/lncidjson', function(data){
this.qtd = data.usuarios.length - 1;
this.valore = '';
this.label = '';
for (i = 0; i < this.qtd; i++){
if(i == (this.qtd - 1)) {
this.valore += data.usuarios[i].valor;
this.label += data.usuarios[i].descr;
}
else {
this.valore += data.usuarios[i].valor + ',';
this.label += data.usuarios[i].descr + ',';
}
}
$('#valor').html(this.valore);
$('#label').html(this.label);
});
}
}
// Objeto.
var obj = new json();
obj.resgatarValores();
To turn an object into json you don’t need to create a class, javascript already does it natively.
– Marcelo Aymone
http://answall.com/q/42809/14674 , http://answall.com/q/5656/14674
– Franchesco
Values are not yet an array they are only assigned to the variable.
– nardo_bruxo
You can use native methods to transform (parse) the information into a JSON.
var seuJson = JSON.parse(valore);
– user20212
Depending on how your object looks of course, if you don’t need to format it to parse.
– Luan Fagundes