Quantcast
Channel: Microsoft Dynamics 365 Community
Viewing all articles
Browse latest Browse all 17314

Testing JSON from AX 2012

$
0
0
I wanted to see how JSON could be consumed from AX, and found this great article from Jonathan.

Then I needed something to test with and found the site jsontest.com.

And so, here are two examples.

The first example just returns your IP address:
static void JSONTestIP(Args _args)
{
RetailWebRequest request;
RetailWebResponse response;
str rawResponse;
Map responseData;
str responseValue;

RetailCommonWebAPI webApi = RetailCommonWebAPI::construct();

request = RetailWebRequest::newUrl("http://ip.jsontest.com");
response = webApi.getResponse(request);

rawResponse = response.parmData();

responseData = RetailCommonWebAPI::getMapFromJsonString(rawResponse);
responseValue = responseData.lookup("ip");

info(strFmt("Element name: %1", responseValue));
}

The next example returns key/value pairs. In this example first name of a person is found based on the persons last name:
static void JSONTestKeyValue(Args _args)
{
RetailWebRequest request;
RetailWebResponse response;
str rawResponse;
Map responseData;
str responseValue;

RetailCommonWebAPI webApi = RetailCommonWebAPI::construct();

request = RetailWebRequest::newUrl("http://echo.jsontest.com/Agermark/Palle/Kent/Clark");
response = webApi.getResponse(request);

rawResponse = response.parmData();

responseData = RetailCommonWebAPI::getMapFromJsonString(rawResponse);
responseValue = responseData.lookup("Kent");

info(strFmt("Element name: %1", responseValue));
}

Viewing all articles
Browse latest Browse all 17314

Latest Images

Trending Articles



Latest Images