JSON Best Way to read them on Dynamics NAV

nav_student
Member Posts: 175
According to NAVTechDays 2017 Json Meets NAV thre are several ways to Read a JSON file
I followed this article https://kauffmann.nl/2015/12/03/web-services-examples-part-2-verify-e-mail-address/
but my JSON has a more complex structure similar with the following example
Could you give me an example I can I extract for instance the city.
thanks for your help.
Manually – but I would not do that • Convert Json to Xml and read with XmlPort and/or DOM Codeunit 6224 • Use JsonTextReader to read Json to a buffer table (Json Buffer, 1236) • Use JObject DotNet to read Json Json readers
I followed this article https://kauffmann.nl/2015/12/03/web-services-examples-part-2-verify-e-mail-address/
but my JSON has a more complex structure similar with the following example
{ "firstName": "Oscar", "lastName": "Smith", "gender": "man", "age": 76, "address": { "streetAddress": "999 Udhna", "city": "ASurt", "state": "GJ", "postalCode": "254221" }, "phoneNumbers": [ { "type": "home", "number": "7383627627" } ] }
Could you give me an example I can I extract for instance the city.
thanks for your help.
0
Answers
-
Hello @nav_student, take a look to this:
https://forum.mibuso.com/discussion/comment/325897#Comment_325897
Regards0 -
Thanks for your reply guys. I used Juhl's approach:
For this type of JSON reply{ "authentication": "windows", "A": [ { "A_A": [ { "A_A_A": { "addressLine": "No. and Street Name", }, } ] } ], "status": 200, }
I used the following code:
Note: Variable counter in this case is always 0 (zero)URL:=Text00; InitializeWebRequest(HttpWebRequestMgt,URL); TempBlob.INIT; TempBlob.Blob.CREATEINSTREAM(Instr); IF HttpWebRequestMgt.GetResponseStream(Instr) THEN BEGIN JsonText := TempBlob.ReadAsText('',TEXTENCODING::UTF8); IF JsonText <> '' THEN BEGIN JObject := JObject.Parse(JsonText); //"statusCode": 200, IF JObject.GetValue('status').ToString <> 'OK' THEN ERROR(JObject.GetValue('statusDescription').ToString); //"A": [ IF NOT ISNULL(JObject.GetValue('A')) THEN BEGIN JObject := JObject.GetValue('A'); IF JObject.HasValues THEN BEGIN TempJObject := JObject.Item(counter); //A_A IF NOT ISNULL(TempJObject.GetValue('A_A')) THEN BEGIN JObject2 := TempJObject.GetValue('A_A'); IF JObject2.HasValues THEN BEGIN TempJObject2 := JObject2.Item(counter); //address TempJObject2:=TempJObject2.GetValue('A_A_A'); MESSAGE(TempJObject2.GetValue('addressLine').ToString); END; END; END; END; END; END; END ELSE MESSAGE(GETLASTERRORTEXT); LOCAL InitializeWebRequest(VAR HttpWebRequestMgt : Codeunit "Http Web Request Mgt.";URL : Text) HttpWebRequestMgt.Initialize(URL); HttpWebRequestMgt.DisableUI; HttpWebRequestMgt.SetMethod('GET'); HttpWebRequestMgt.SetTimeout(60000 * 3); HttpWebRequestMgt.SetReturnType('application/json'); HttpWebRequestMgt.SetContentLength(0);
2 -
Do you have an example of POST methode?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