C# force integer when converting XML to JSON -


i attempting convert xml json in order generate http post request api. getting error because 1 of fields meant integer instead of string. have read adding "json:integer="true"" node cause become int, doesnt seem working me. here xml , resulting json. arrays working, integer not.

<shipments json:array="true" xmlns:json="http://james.newtonking.com/projects/json">     <shipment_tracking_number />     <response_shipment_date>2016-10-18t01:00:00.0000000-04:00</response_shipment_date>     <response_shipment_method>ups ground</response_shipment_method>     <expected_delivery_date>2016-10-18t01:00:00.0000000-04:00</expected_delivery_date>     <ship_from_zip_code>12345</ship_from_zip_code>     <carrier_pick_up_date>2016-10-18t01:00:00.0000000-04:00</carrier_pick_up_date>     <carrier>ups</carrier>     <shipment_items json:array="true">         <shipment_item_id>ff12345k</shipment_item_id>         <alt_shipment_item_id>1234567890</alt_shipment_item_id>         <merchant_sku>b00xxxx</merchant_sku>         <response_shipment_sku_quantity json:integer="true">1</response_shipment_sku_quantity>     </shipment_items> </shipments> 

string jsonrequest = jsonconvert.serializexmlnode(doc, newtonsoft.json.formatting.none, true);

{"shipments":[     {         "shipment_tracking_number":null,         "response_shipment_date":"2016-10-18t01:00:00.0000000-04:00",         "response_shipment_method":"ups ground",         "expected_delivery_date":"2016-10-18t01:00:00.0000000-04:00",         "ship_from_zip_code":"12345",         "carrier_pick_up_date":"2016-10-18t01:00:00.0000000-04:00",         "carrier":"ups",         "shipment_items":[         {             "shipment_item_id":"ff12345k",             "alt_shipment_item_id":"1234567890",             "merchant_sku":"b00xxxx",             "response_shipment_sku_quantity":"1"         }]     }] } 

i need "response_shipment_sku_quantity":"1" show "response_shipment_sku_quantity":1, doesnt seem working. can modify xml or code performs conversion. dont mind long can done.

you define attribute wrongly. how should like.

<response_shipment_sku_quantity json:type='integer'>1</response_shipment_sku_quantity> 

edit:

newtonsoft.json xmlnodeconverter

look methods private void serializenode , string datatype = getdatatype(node); suggest definition.

another option deserialize xml class proper types properties , after serialize json.


Comments

Popular posts from this blog

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -