1
I have the following json
[
{"name":"razao_social","value":"INTELIDER"},
{"name":"nome_fantasia","value":"INTELIDER LTDA"},
{"name":"cpf_cnpj","value":"10.999.558/0001-86"},
{"name":"rg_insc_estadual","value":"132456789"},
{"name":"login","value":"gleyson"},
{"name":"senha","value":"123456"},
{"name":"confirma_senha","value":"S"}
]
need convert to the object below:
[
{
"razao_social": "INTELIDER",
"nome_fantasia": "INTELIDER LTDA",
"cpf_cnpj": "10999558000186",
"rg_insc_estadual": "132456789",
"usuario": {
"login": "gleyson",
"senha": "123456",
"ativo": "S"
},
}
]
Hiago passed me the following code:
$('.form').submit(function () {
var dados = jQuery(this).serializeArray();
var obj = {};
$.each(dados, function (i,obj) {
obj[obj.name] = obj.value;
});
obj.usuario = {
login: obj.login,
senha: obj.senha,
ativo: obj.confirma_senha
};
var json = JSON.stringify([obj]);
alert(json);
return false;
});
In the end the return is empty [{"user":{}}], but debugging I see that the data array is filled correctly, it also enters in $.each, and loads the values passes the values and Zera one by one.