I have the following well formed JSON string
{"paymentType": 1, "payer": john doe, "currency": 1, "receiptId": 4, "amount": [{"invoiceFeeId": 12080, "amountPaid": 120},{"invoiceFeeId": 12079, "amountPaid": 200},{"invoiceFeeId": 12078, "amountPaid": 500}] }
However i can’t seem to parse it into a javascript object before submiting a form like this.
var paymentFormSearialized = '{"paymentType": '+$("#paymentForm #paymentType").val()+', "payer": '+$("#paymentForm #payer").val()+
', "currency": '+$("#paymentForm #currency").val()+', "receiptId": '+$("#receiptId").val()+', "amount": ['+amountsasjson+'] }';
$.post("<c:url value='/payments/create/${invoiceId}'/>", $.parseJSON(paymentFormSearialized ), function(data){
alert(data);
});
The post data must be a JSON object, out of desperation I even tried using eval().
Please help, maybe I am not seeing someting in my string?
That is not well formed, you have unquoted strings. Besides why do you need to make a clumsy string and parse it into an object, when you can make an object to begin with?