0

I am using JSON stringify, here is my code:

var lista={};
    for(var i=0; i < arr.length; i++){
        lista[i]=[];
        //lista[i].push('imagen:'+arr[i].id);
        lista[i].push('nick:'+arr[i].nick); 
        lista[i].push('tlfno:'+arr[i].tlfno);
        lista[i].push('nombre:'+arr[i].nombre);
        lista[i].push('descripcion:'+arr[i].descripcion);
        lista[i].push('direccion:'+arr[i].direccion);
        lista[i].push('fecha:'+arr[i].fecha);
        lista[i].push('estado:'+arr[i].estado);
        lista[i].push('tipoimagen:'+arr[i].tipoimagen);
        //lista[i].push('imagen:'+arr[i].imagen);
    }
    var json = JSON.stringify(lista);
    console.log(json);

I am getting this output:

{"0":["nick:pepe","tlfno:678909897","nombre:dsfdfsf","descripcion:dsdsdsd","direccion:fdfdf","fecha:fdfdf","estado:1","tipoimagen:image/jpeg"]

but is wrong because it would be like this:

{"0":["nick":"pepe" with double quotes, somebody knows how to show this double quote? Thanks

2
  • take a look here json.org ... so you might understand JSON better Commented May 6, 2014 at 15:25
  • haven't you what you want already in arr? Try out JSON.stringify(arr). Commented May 6, 2014 at 15:28

1 Answer 1

3

I'm guessing you're trying to push objects into that array, not strings

lista[i].push( {nick: arr[i].nick} );

That would give you something like

{"0":[{"nick":"pepe"}]}

note that {"0":["nick":"pepe"... is not valid, so you won't be getting that

FIDDLE

Sign up to request clarification or add additional context in comments.

1 Comment

adeneo hit it right on the head - in the line lista[i].push('nick:'+arr[i].nick); , you're pushing the string 'nick: pepe', instead of an object.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.