I have been using SOAP services over the last years. Only recently the RESTful web services have become more and more popular in my integration work. Wikipedia says:
In computing, Representational State Transfer (REST) is a software architecture style for building scalable web services. REST gives a coordinated set of constraints to the design of components in a distributed hypermedia system that can lead to a higher performing and more maintainable architecture.
RESTful systems typically, but not always, communicate over the Hypertext Transfer Protocol with the same HTTP verbs (GET, POST, PUT, DELETE, etc.) which web browsers use to retrieve web pages and to send data to remote servers. REST interfaces usually involve collections of resources with identifiers, for example /people/paul, which can be operated upon using standard verbs, such as DELETE /people/paul.
As we are used to XML as the body for our SOAP messages we can also use XML as the body for a RESTful web service. I just finished writing a code to communicate with Azure from NAV. This communication was using RESTful web services and XML.
So, what is JSON? Wikipedia says:
The JSON format was originally specified by Douglas Crockford. It is currently described by two competing standards, RFC 7159 and ECMA-404. The ECMA standard is minimal, describing only the allowed grammar syntax, whereas the RFC also provides some semantic and security considerations. The official Internet media type for JSON is application/json. The JSON filename extension is .json.
With JSON it is possible to deliver similar data structure as with XML. JSON on the other hand requires a much less metadata. Here is an example JSON from Wikipedia:
"streetAddress": "21 2nd Street",
"city": "New York",
"number": "212 555-1234"
"number": "646 555-4567"
There is not a good support for JSON in native .NET from Microsoft. However, with Visual Studio, Microsoft installs an external DLL in to the folder “C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\PrivateAssemblies”
With this Json.NET in Dynamics NAV Add-ins folder we now have some way to handle JSON files. Using this Add-in I created a NAV Codeunit to manage JSON text.
This Codeunit contains functions to build a JSON document, like
Json := Json.Copy(GetJSon);[/code]
A function to import values from a JSON document to a temporary table, like
WITH TempPostingExchField DO BEGIN
SETCURRENTKEY("Line No.","Column No.");
IF FIND(‘-‘) THEN REPEAT
SETRANGE("Column No.","Column No.");
UNTIL NEXT = 0;
Or just a simple way to return a single value from a simple JSON string, like
[code lang=”csharp”]FileName := GetValueFromJsonString(String,’filename’);[/code]
With these functions NAV should be able to handle JSON files without any problems.
Now you can add JSON handling to your arsenal.