Adding nodes with JsonTextWritter

AitorEG
Member Posts: 342
Hi everyone,
Probably is an easy question, but I can't find the way to do this. This is the structure of an XMLPort:

I need to generate a JSON with that structure, and I'm trying in this way:
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
Probably is an easy question, but I can't find the way to do this. This is the structure of an XMLPort:

I need to generate a JSON with that structure, and I'm trying in this way:
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;
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
0
Answers
-
This is my new code:
JSonResponse := JSonResponse.JObject(); JsonTextWriter := JSonResponse.CreateWriter(); JsonTextWriter.Formatting := 1; JsonTextWriter.WriteValue(peShopItem."Weight (Kg)"); JsonTextWriter.WritePropertyName('ByShop'); JsonTextWriter.WriteStartObject; leShopItembyShop.RESET; leShopItembyShop.SETRANGE("Item No.",peShopItem."No."); IF leShopItembyShop.FINDSET THEN REPEAT JsonTextWriter.WritePropertyName('eShopURL'); JsonTextWriter.WriteValue(leShopItembyShop."eShop URL"); UNTIL leShopItembyShop.NEXT = 0; JsonTextWriter.WriteEndObject;
I know that There will always be 2 leShopItembyShop ocurrences, but it jsut writes the last one...
May be the jsontextwritter is overwritting?0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions