在AX中解析多层的json信息
程序员文章站
2022-08-05 07:50:08
str jsonstr ='{"FieldValues":[{"FieldName":"Field1","FieldValue":"Rec1Field1Value"},'+ '{"FieldName":"Field2","FieldValue":"Rec1Field2Value"}]}'; Map ......
str jsonstr ='{"fieldvalues":[{"fieldname":"field1","fieldvalue":"rec1field1value"},'+
'{"fieldname":"field2","fieldvalue":"rec1field2value"}]}';
map jsonmap, linemap;
container linecon;
container itemscon;
listenumerator listenumerator;
mapenumerator mapenumerator;
list linelist;
;
jsonmap = retailcommonwebapi::getmapfromjsonstring(jsonstr);
'{"fieldname":"field2","fieldvalue":"rec1field2value"}]}';
map jsonmap, linemap;
container linecon;
container itemscon;
listenumerator listenumerator;
mapenumerator mapenumerator;
list linelist;
;
jsonmap = retailcommonwebapi::getmapfromjsonstring(jsonstr);
if (jsonmap.exists("fieldvalues"))
{
itemscon = jsonmap.lookup("fieldvalues");
linelist = list::create(itemscon);
listenumerator = linelist.getenumerator();
{
itemscon = jsonmap.lookup("fieldvalues");
linelist = list::create(itemscon);
listenumerator = linelist.getenumerator();
while (listenumerator.movenext())
{
linecon = listenumerator.current();
linemap = map::create(linecon);
info(linemap.lookup("fieldname"));
info(linemap.lookup("fieldvalue"));
}
}
{
linecon = listenumerator.current();
linemap = map::create(linecon);
info(linemap.lookup("fieldname"));
info(linemap.lookup("fieldvalue"));
}
}