I have observed that in php you can encode an array and the resulting json does not carry the square brackets.However,in my javascript array,
var arrCars = new Array("Toyota", "Mercedes", "BMW");
var jsonStr = JSON.stringify(arrCars);
alert(jsonStr);
i keep getting the square brackets.I have also noticed that if i use json stringfy,
var foo = {};
foo.bar = "new property";
foo.baz = 3;
var JSONfoo = JSON.stringify(foo);
i get the json without the square just like i wanted.What must i do to my array to do away with the brackets?.
echo json_encode(array("item1", "item2", "item3"));gives me the expected["item1","item2","item3"]. Also, why would you want to get rid of the brackets? They are a crucial part of JSON.JSON.stringify(arrCars).replace(/[\[\]]/g,'')you should probably be more careful/selective about how you do that, but just as a simple example