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; }
Answers
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 needs