Need help with creating a nested JSON
Hi,
The JSON format I would like to send is like this:
{"InvoiceID": "12345",
"InvoiceLine": [{"Description": "Item1", "Quantity": 1, "LineTotal": 20} ,
{"Description": "Item2", "Quantity": 2, "LineTotal": 15} ]
}
I tried to create the above by
<cfset LineInfo =' {"Description": "Item1", "Quantity": 1, "LineTotal": 20} ,
{"Description": "Item2", "Quantity": 2, "LineTotal": 15} '>
This is done after some looping to find out the number of lines I have.
<cfscript>
myStruct=
{"InvoiceID": "12345",
"InvoiceLine": [#LineInfo#]
}
</cfscript>
Then, #serialize JSON(myStruct)# becomes
{"InvoiceID": "12345", "InvoiceLine": ["{\"Description\": \"Item1\", \"Quantity\": 1, \"LineTotal\": 20} ,
{\"Description\": \"Item2\", \"Quantity\": 2, \"LineTotal\": 15} "]}
The problem seems to be the double quotation after [ and before ], or before and after #LineInfo# as above.
Question is how can I generate the nested JSON format I need? I need to do a looop of some sort to find out how many Lines I have.
Any insights?
Thanks!
Dchan
#JSON #CF2016
