Deserializing JSON in AX 2012 using X++ code

Hi All,

I have the following JSON message and I need to deserailize it uisng X++ code…


ContactPersonID

ContactTypeId

OrderId

209674

SPD



209674

Senior Contact



209674

x



209674

y



209674

z

ORD-05238-C9K3H2

209674

u

ORD-05240-H7M1K7

The message looks like this:
{
“entities”:[
{
“_Tablename”:“ECL_ContactPersonType”,
“ContactPersonID”:“209674”,
“OrderNumbers”:[
{
“OrderNumber”:"",
“RelatedRecords”:[

{

“ContactType”:“SPD”,

“OrderNumber”:""

},

{

“ContactType”:“Senior Contact”,

“OrderNumber”:""

},

{

“ContactType”:“x”,

“OrderNumber”:""

},

{

“ContactType”:“y”,

“OrderNumber”:""

}

]

},
{
“OrderNumber”:“ORD-05238-C9K3H2”,
“RelatedRecords”:[

{

“ContactType”:“z”,

“OrderNumber”:“ORD-05238-C9K3H2”

}

]

},
{
“OrderNumber”:“ORD-05240-H7M1K7”,
“RelatedRecords”:[

{

“ContactType”:“u”,

“OrderNumber”:“ORD-05240-H7M1K7”

}

]

}
]
}
]
}
Thanks in Advance…

Check whether RetailCommonWebAPI::getMapFromJsonString() can’t help.

If not, I think the easiest thing is doing it in a C# class library added to AOT. There you can easily generate classes from JSON and deserialize the text to them.

Create a library, add a class, put the JSON string to clipboard and use Edit > Paste special > Paste JSON as classes. This will create all necessary classes for you; rename them as needed.

Deserialization from JSON to the classes can be done with Newtonsoft.JSON, namely JSONConver.DeserializeObject().