Purpose
Reading Json in Microsoft Dynamics AX/D365 is very common requirement in integration.Here we will use standard AX/D365 class RetailCommonWebAPI for reading JSON string.
Sample Code
[code language=”cpp”]
static void readJSON(Args _args)
{
mapEnumerator mapEnumerator;
Map data;
List testList;
str _jsonStr;
container test;
ListEnumerator listEnumerator;
int containerList;
Map map1;
int lengthIterate;
;
_jsonStr = ‘{“branchList”:[“601″,”602″,”603″,”604”]}’;
data = RetailCommonWebAPI::getMapFromJsonString(_jsonStr);
mapEnumerator = data.getEnumerator();
while (mapEnumerator.moveNext())
{
switch (mapEnumerator.currentKey())
{
case “branchList” :
test = mapEnumerator.currentValue();
testList =List::create(test);
listEnumerator = testList.getEnumerator();
while (listEnumerator.moveNext())
{
test = listEnumerator.current();
info(conpeek(test, 1));
}
break;
}
}
}
[/code]
Cheers 🙂
Piyush Adhikari
Awesome information Piyush. Nice post