Hi,
I started working with API responses with Business Central. The Response has nested arrays. I want to use JsonObject to get access to the last array. At this point I convert the response to text and then I manually strip the results line by line. This has some risks, but I want to use the right way with the JsonObject.
I can send the parameters to the API and I get a response. The response is converted to JsonObject.
The problem I have is that I want to use the travel Distance in the results array but I'm unable to use the path; There is going to be N amount of results depending on the input. I want to get the value of all the TravelDistance ....The path should end with "results[N].travelDistance".
This is what I tried thus far.
The Image above gave me a list in Tokens, but its worthless.
Next I tried to use the result of token as a text value to step down but the different arrays but no luck.
I used a Jsonpath Finder to get the path that I want to use ,but BC does not recognise the path when using JObject.path('resourceSets[0].resources[0].results[2].travelDistance');
The path retrieved was : (x..resourceSets[0].resources[0].results[2].travelDistance)
The response Looks as follow:
{
"authenticationResultCode": "ValidCredentials",
"brandLogoUri": "">dev.virtualearth.net/.../logo_powered_by.png",
"copyright": "Copyright © 2022 Microsoft and its suppliers. All rights reserved. This API cannot be accessed and the content and any results may not be used, reproduced or transmitted in any manner without express written permission from Microsoft Corporation.",
"resourceSets": [
{
"estimatedTotal": 1,
"resources": [
{
"__type": "DistanceMatrix:http://schemas.microsoft.com/search/local/ws/rest/v1",
"destinations": [
{
"latitude": ######,
"longitude":######
},
{
"latitude": ######,
"longitude": ######
}
],
"origins": [
{
"latitude": ######,
"longitude":########
},
{
"latitude": #####,
"longitude": #####
}
],
"results": [
{
"destinationIndex": 0,
"originIndex": 0,
"totalWalkDuration": 0,
"travelDistance": 0,
"travelDuration": 0
},
{
"destinationIndex": 1,
"originIndex": 0,
"totalWalkDuration": 0,
"travelDistance": 44.109,
"travelDuration": 43.7167
},
{
"destinationIndex": 0,
"originIndex": 1,
"totalWalkDuration": 0,
"travelDistance": 43.971,
"travelDuration": 42.9
},
{
"destinationIndex": 1,
"originIndex": 1,
"totalWalkDuration": 0,
"travelDistance": 0,
"travelDuration": 0
}
]
}
]
}
],
"statusCode": ###,
"statusDescription": "OK",
"traceId": "######"
}
Thank you in Advance