c# - Figure up how to implement dynamic JSON manipulation -
my issue this:
i trying send json represent order api.
this structure of problem facing
and examples of orders:
- multiply shipment , items, orders
- one shipment , multiply items, orders
- one shipment , 1 item, order
-> hoping covered cases
this json built xml, built dynamically each time customer wants order something.
- he can order, multiply shipment, , multiply items - function needs take care of it.
i having trouble struct function handle case , write correct id's.
for wrote(i writing values xml , serialize json of newtonsoft
- working fine)
public void sendorder(string renderedoutput, string orderid) { var xml = xelement.parse(renderedoutput); var elmorderdata = xml.element("orderdata").descendants(); var shipmentsids = getshipmentsids(orderid); int shipmentid = 0; int shipmentid_index = 0; foreach (var el in elmorderdata) {// correct order according xml template if (el.name == "shipmentindex" && el.attribute("name").value == "items") {// items -> shipmentindex el.setvalue(shipmentid); } if (el.name == "shipmentindex" && el.attribute("name").value == "shipments") {// shipments -> shipmentindex el.setvalue(shipmentid); } if (el.name == "sourceshipmentid") { var sourceshipmentindex = shipmentsids[shipmentid_index]; el.setvalue(sourceshipmentindex); shipmentid++; shipmentid_index++; } } }
Comments
Post a Comment