Источник:
http://www.agermark.com/2015/01/test...m-ax-2012.html
==============
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:
X++:
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:
X++:
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));
}
Источник:
http://www.agermark.com/2015/01/test...m-ax-2012.html