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

Announcements

No record found.

News and Announcements icon
Community site session details

Community site session details

Session Id :
Microsoft Dynamics AX (Archived)

JSON String to Axapta MAP

(0) ShareShare
ReportReport
Posted on by

I have the below JSON string, which I am converting to a map and then reading the values based on the keys

str json = '{"PortalId" : "POR146", 
             "MemberId" : "MEM132", 
             "ParmContainer": [{"Key1":"First",
                                "Key2":"Second"},
                               {"Key1":"Third",
                                "Key2":"Fourth"}]}';


I am able to read the keys and values using the RetailCommonWebAPI::getMapFromJSONString.

The problem that I have is reading the values inside the parmContainer key. From the documentation that I found, the keys are stored as strings, and values are stored as containers. When I look inside the container, I get integer values instead of "First", "Second", "Third" and "Fourth".

while ( mapEnumerator.moveNext())
        {
            switch (mapEnumerator.currentKey().ToString())
            {
                case "ParmContainer"     :
                container test = mapEnumerator.currentValue();
                info(conPeek(test,1));
                info(conPeek(test,2));
                info(conPeek(test,3));
                info(conPeek(test,4));
            }
        }


Any ideas on how to solve this issue please?

*This post is locked for comments

I have the same question (0)
  • Suggested answer
    Martin Dráb Profile Picture
    239,029 Most Valuable Professional on at

    I would rather use classes. For example, you can create a C# class library, then generate classes by Edit > Paste Special > Paste JSON as Classes, use Newtonsoft.Json to parse the JSON string to these classes and use them in X++.

    Welcome to the world of .NET, full of options. :-)

  • Verified answer
    Community Member Profile Picture
    on at
    static void Job24(Args _args)
    {
        str json = '{"PortalId" : "POR146",          "MemberId" : "MEM132", "ParmContainer": [{"Key1":"First", "Key2":"Second"}, {"Key1":"Third","Key2":"Fourth"}]}';
        Map map;
        Map map1;
        List testList;
        
        ListEnumerator listEnumerator;
        container test;
        mapEnumerator mapEnumerator;
        map = RetailCommonWebAPI::getMapFromJsonString(json);
    
        mapEnumerator = map.getEnumerator();
        while ( mapEnumerator.moveNext())
            {
                switch (mapEnumerator.currentKey())
                {
                    case "ParmContainer"     :
                    test = mapEnumerator.currentValue();
    
                    testList =List::create(test);
    
                    listEnumerator = testList.getEnumerator();
    
                    while (listEnumerator.moveNext())
                    {
                        test = listEnumerator.current();
                        map1 = Map::create(test);
                        info(map1.lookup('Key1'));
                        info(map1.lookup('Key2'));
                    }
                }
            }
    }

    ?

  • Community Member Profile Picture
    on at

    Brilliant thanks, exactly what i needed!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Stars!

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > 🔒一 Microsoft Dynamics AX (Archived)

#1
Joris dG Profile Picture

Joris dG 5

#2
Alexey Lekanov Profile Picture

Alexey Lekanov 2

#2
Henrik Nordlöf Profile Picture

Henrik Nordlöf 2 User Group Leader

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans