Hi everyone,
Probably is an easy question, but I can't find the way to do this. This is the structure of an XML
The resultant Json should be like this:
{ "@xmlns": "<urn:microsoft-dynamics-nav/xmlports/eShopItem", "eShopItem": [ { "@Ref": "4802-31", "@DeleteForEshop": "false", "@Picture1": "http://www.xxxxxx.com/epicture/xx/4802-31.jpg", "@Category": "Ixxxx", "@Subcategory": "", "@SubcDescription": "", "@Range": "24\"", "@Reading": "", "@WeightKg": "0.070", "ByShop": [ { "@eShopURL": "eShop1", "@Enabled": "true", "@Description": "RADIUS GAGE", "@Availability": "8", "@GenericPrice": "0.00", "@InTransit": "50", "@FromTransitDate": "2019-05-20", "@InCentral": "0", "@FromCentralDate": "", "@FromCentralDateText": "", "@URLTechnicalCard": "http://www.xxxx.com/pdf/xxx/4802.pdf" }, { "@eShopURL": "eShop2", "@Enabled": "true", "@Description": "Medidor de Radios 25-40 mm", "@Availability": "8", "@GenericPrice": "0.00", "@InTransit": "50", "@FromTransitDate": "2019-05-20", "@InCentral": "0", "@FromCentralDate": "", "@FromCentralDateText": "", "@URLTechnicalCard": "http://www.xxxxxx.com/pdf/xxxxx/esp/4802.pdf" } ] }
And I'm trying to code like this:
LOCAL CreateSimpleJsonFile(VAR JSonResponse : DotNet "Newtonsoft.Json.Linq.JObject";peShopItem : Record "eShop Item") JSonResponse := JSonResponse.JObject(); JsonTextWriter := JSonResponse.CreateWriter(); JsonTextWriter.WritePropertyName('Ref'); JsonTextWriter.WriteValue(peShopItem."No."); JsonTextWriter.WritePropertyName('DeleForEshop'); JsonTextWriter.WriteValue(peShopItem."Delete-for Eshop"); JsonTextWriter.WritePropertyName('Picture1'); JsonTextWriter.WriteValue(peShopItem."Picture 1"); JsonTextWriter.WritePropertyName('Category'); JsonTextWriter.WriteValue(peShopItem."Item Category Code"); JsonTextWriter.WritePropertyName('Subcategory'); JsonTextWriter.WriteValue(peShopItem."Product Group Code"); JsonTextWriter.WritePropertyName('SubcDescription'); JsonTextWriter.WriteValue(peShopItem."Item Group Description"); JsonTextWriter.WritePropertyName('Range'); JsonTextWriter.WriteValue(peShopItem.Range); JsonTextWriter.WritePropertyName('Reading'); JsonTextWriter.WriteValue(peShopItem.Reading); JsonTextWriter.WritePropertyName('WeightKg'); JsonTextWriter.WriteValue(peShopItem."Weight (Kg)"); leShopItembyShop.RESET; leShopItembyShop.SETRANGE("Item No.",peShopItem."No."); IF leShopItembyShop.FINDSET THEN REPEAT JsonTextWriter.WritePropertyName('eShopURL'); JsonTextWriter.WriteValue(leShopItembyShop."eShop URL"); JsonTextWriter.WritePropertyName('Enabled'); JsonTextWriter.WriteValue(leShopItembyShop.Enabled); JsonTextWriter.WritePropertyName('Description'); JsonTextWriter.WriteValue(leShopItembyShop.Description); JsonTextWriter.WritePropertyName('Availability'); JsonTextWriter.WriteValue(leShopItembyShop.Availability); JsonTextWriter.WritePropertyName('GenericPrice'); JsonTextWriter.WriteValue(leShopItembyShop."Generic Price"); JsonTextWriter.WritePropertyName('InTransit'); JsonTextWriter.WriteValue(leShopItembyShop."Qty. on Purch. Order"); JsonTextWriter.WritePropertyName('FromTransitDate'); JsonTextWriter.WriteValue(leShopItembyShop."Next Reception Date"); JsonTextWriter.WritePropertyName('InCentral'); JsonTextWriter.WriteValue(leShopItembyShop."Qty. on Origin"); JsonTextWriter.WritePropertyName('FromCentralDate'); JsonTextWriter.WriteValue(leShopItembyShop."Recep. Date-from Origin"); JsonTextWriter.WritePropertyName('FromCentralDateText'); JsonTextWriter.WriteValue(leShopItembyShop."Recep.-from Origin (Text)"); JsonTextWriter.WritePropertyName('URLTechnicalCard'); JsonTextWriter.WriteValue(leShopItembyShop."Technical Card url"); UNTIL leShopItembyShop.NEXT = 0;
With this code, I obtain this file:
{ "Ref": "1108-150", "DeleForEshop": false, "Picture1": "www.xxxx.com/.../1108-150W.jpg", "Category": "INSIZE", "Subcategory": "02", "SubcDescription": "Calibres", "Range": "0-150mm/0-6\"", "Reading": "0.01mm/0.0005\"", "WeightKg": 0.3875, "eShopURL": "eShop2", "Enabled": true, "Description": "Calibre Digital 0-150mm/0-6\"", "Availability": 335.0, "GenericPrice": 0.0, "InTransit": 0.0, "FromTransitDate": "0001-01-01T00:00:00", "InCentral": 0.0, "FromCentralDate": "0001-01-01T00:00:00", "FromCentralDateText": "", "URLTechnicalCard": "www.xxx.com/.../1108.pdf" }{ "Ref": "1108-150W", "DeleForEshop": false, "Picture1": "www.xxxx.com/.../1108-150W.JPG", "Category": "INSIZE", "Subcategory": "02", "SubcDescription": "Calibres", "Range": "0-150mm/0-6\"", "Reading": "0.01mm/0.0005\"", "WeightKg": 0.3835, "eShopURL": "eShop2", "Enabled": true, "Description": "Calibre Digital Sin Ruleta 0-150mm/0-6\"", "Availability": 585.0, "GenericPrice": 0.0, "InTransit": 0.0, "FromTransitDate": "0001-01-01T00:00:00", "InCentral": 0.0, "FromCentralDate": "0001-01-01T00:00:00", "FromCentralDateText": "", "URLTechnicalCard": "www.xxxx.com/.../1108.pdf" }{
As you can imagine, after the findset I should create another deeper level of the json, but this is not working. What sentence should I use?
Thank you very much
*This post is locked for comments