Deserialize Json as an array/list of results

Krips
Member Posts: 4
Hi,
I am trying to call a Rest web service, which returns response in the form of a json
"Result": [
{"id":"1", "firstname":"xyz"},
{"id":"2", "firstname":"abc"}
]
I have created a dotnet dll and imported it into navision.
I use the ApiResult := JsonConvert.DeserializeObject(Json,GETDOTNETTYPE(ApiResult)); to deserialize the Json where ApiResult is set to the rootObject.
How can I store the result in an array or list and access it in C/AL?
I am trying to call a Rest web service, which returns response in the form of a json
"Result": [
{"id":"1", "firstname":"xyz"},
{"id":"2", "firstname":"abc"}
]
I have created a dotnet dll and imported it into navision.
I use the ApiResult := JsonConvert.DeserializeObject(Json,GETDOTNETTYPE(ApiResult)); to deserialize the Json where ApiResult is set to the rootObject.
How can I store the result in an array or list and access it in C/AL?
1
Answers
-
Any progress on this? I have the exact same issue I am working on. I'll post a response if I figure it out.1
-
I have a solution to use
JToken := JToken.Parse(Json);
ResultList := JToken.SelectToken('Result');
Then I just loop through the ResultList to get values. This approach works fine.
But I am still not able to use the Deserialize Json.
I have been referring to this blog as well https://www.ctrlshiftf4.com/2017/05/17/consume-openweather-rest-api-in-dynamics-nav/ which has been quite helpful for starters.
But the structure of the json is just a single object and not many objects.0 -
HiI have a solution to use
JToken := JToken.Parse(Json);
ResultList := JToken.SelectToken('Result');
Then I just loop through the ResultList to get values. This approach works fine.
But I am still not able to use the Deserialize Json.
I have been referring to this blog as well https://www.ctrlshiftf4.com/2017/05/17/consume-openweather-rest-api-in-dynamics-nav/ which has been quite helpful for starters.
But the structure of the json is just a single object and not many objects.
How you do loop through the ResultList to get values??0 -
I know, this is an AL example, but I am already converting the sample solution to a C/AL version as well:
https://www.kauffmann.nl/2017/06/24/al-support-for-rest-web-services/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