Ok, this question may be dumb, but I'm really stuck with this.
I want to a json structure like the following:
order: {
currency: 'eur',
order_items: [
{
id: 3,
quantity: 1
},
{
id: 67,
quantity: 1
}
]
}
What I'm doing right now is this:
function makeOrder(){
var myArray = new Array();
for(var i=0;i<bookedItemsArray.length;i++){
var newObject = new OrderedItem(bookedItemsArray[i].id, bookedItemsArray[i].amount);
myArray.push(newObject);
}
var mystring = JSON.stringify(myArray);
//myString = "order: {currency: 'eur', order_items: " + myString + "}";
console.log(myString);
}
The way I get the data inside the order_items array is being cool, but when I try to concat the array with the rest (line in comments), I get:
?:??: W/?(?): Uncaught SyntaxError: Unexpected token ILLEGAL at file:///android_asset/www/november/js/t03/Booking/bookingProcess.js:96
Is there something I'm missing about the way a string and a JSON structure can be combined?
Thank you very much.
JSON.stringify(myArray)
should always produce a valid JSON string unless the argument cannot be encoded. – Jan Dvorak Nov 20 '12 at 10:04