JSONBuffer

SteveDesmedt
Member Posts: 3
Dear all,
I'm trying to read a JSon File withing the JsonBuffer table.
The structure of my Json is the following :

What i'm trying to achieve is getting the coordinates out of the Json file to store into database fields.
I'm trying to achieve this by the following code :
My JSONBuffer containsfollowing records :

Hopefully, someone can tell me what i'm doing wrong or what i have to do too get the coordinates as result.
Kind regards
Steve
I'm trying to read a JSon File withing the JsonBuffer table.
The structure of my Json is the following :

What i'm trying to achieve is getting the coordinates out of the Json file to store into database fields.
I'm trying to achieve this by the following code :
codeunit 50112 HttpGeoCodingMgmt { procedure GetLongLat() var uri: Text; ResponseInReadibleFormat: Text; begin uri := 'http://dev.virtualearth.net/REST/v1/Locations/*******************************'; CallExternalWebService(uri, ResponseInReadibleFormat); GetResultofWebservice(ResponseInReadibleFormat); end; local procedure CallExternalWebService(uri: Text; var ResponseInReadibleFormat: Text) var RequestMessage: HttpRequestMessage; HttpClient: HttpClient; ResponseMessage: HttpResponseMessage; Content: HttpContent; begin RequestMessage.Method := 'GET'; RequestMessage.SetRequestUri(uri); HttpClient.Send(RequestMessage, ResponseMessage); Content := ResponseMessage.Content; Content.ReadAs(ResponseInReadibleFormat); end; local procedure GetResultOfWebservice(var ResponseInReadableFormat: Text) var JsonBuffer: Record "JSON Buffer" temporary; TokenSearchText: text; GeoCodeResult: Text; begin TokenSearchText := 'coordinates'; JsonBuffer.ReadFromText(ResponseInReadableFormat); // JsonBuffer.GetPropertyValue(GeoCodeResult, TokenSearchText); // message('%1',GeoCodeResult); JsonBuffer.FindArray(JsonBuffer, TokenSearchText); end; }
My JSONBuffer containsfollowing records :

Hopefully, someone can tell me what i'm doing wrong or what i have to do too get the coordinates as result.
Kind regards
Steve
0
Answers
-
Hey Steve,
If you look at the JSON Buffer table, you can find the definitions of the functions GetPropertyValue, GetPropertyValueAtPath and FindArray
The first attempt, using GetPropertyValue doesn't work because it finds your "coordinates" element (Entry No. = 31) and then returns the value of the next (Entry No +1) element, which is Entry No. 32 and only describes the start of the array. While you need elements 33 and 34.
Using FindArray doesn't succeed because the path is not found (it looks for "coordinates[*" and can't find any).
You could use GetPropertyValueAtPath with the precise path you know "resourceSets[0].resources[0].point.coordinates[0]" and "<..>coordinates[1]", or play around with arrays, going down one level at a time. Alternatively, you could make your own implementation of these functions to suit your needs0
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