jquery - With JSON.stringifyf how do I add square brackets? -
i have code produces json string
{"did":50,"pid":"66","cid":"2","qty":1,"skus":{"ssid":"b931627", "type":"fab" ,"qty":1,"style":""}}
but need format
{"did":50,"pid":"66","cid":"2","qty":1,"skus":[{"ssid":"b931627", "type":"fab" ,"qty":1,"style":""}]}
here have far:
var dataattributes = { did : $(selector).data('did'), pid : $(selector).data('pid'), cid : $(selector).data('cid'), qty : '1', coveroptionskus : var ssus = { ssid : $(selector).data('ssid'), type : '', qty : 1, style : '' } };
added ""
double quotes around dataattributes
property names , values
var dataattributes = { "did" : $(selector).data("did"), "pid" : $(selector).data("pid"), "cid" : $(selector).data("cid"), "qty" : "1", // removed `var` // set `skus` property `array`, // set properties of object // within `skus` array "skus" : [{ "ssid" : $(selector).data("ssid"), "type" : "", "qty" : 1, "style" : "" }] }; // call `json.stringify()` `dataattributes` parameter json.stringify(dataattributes);
Comments
Post a Comment