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:

  1. multiply shipment , items, orders
  2. one shipment , multiply items, orders
  3. 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

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -