web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :

Testing JSON from AX 2012

PA-22040759-0 Profile Picture PA-22040759-0 6,194
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));
}

Comments

*This post is locked for comments