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

Notifications

Announcements

No record found.

Community site session details

Community site session details

Session Id :
Microsoft Dynamics NAV (Archived)

How to iterate over JSON array in Navison 2018 using C/AL

(0) ShareShare
ReportReport
Posted on by 256

Hi All,

I need to iterate over JSONArray in Nav2018, following is the JSON Array snippet.

JSON Data:

{
"return": [
{
"id": 1,
"first_name": "aaa",
"last_name": "ddd",
},
{
"id": 2,
"first_name": "bbb",
"last_name": "eee",
},
{
"id": 3,
"first_name": "ccc",
"last_name": "ttt",
}
]
}

Here I need to insert each "id" data like id, first_name,last_name as a row in the database table.

Thanks in advance.

*This post is locked for comments

I have the same question (0)
  • Verified answer
    I Gusti Made Ari Profile Picture
    3,600 on at

    Hi, you can use codeunit JSONManagement to do that .

    Sample code :

    //Create JSONArray String
    JSONManagement.InitializeFromString(JsonString); JSONManagement.GetJSONObject(JObject); ArrayString := JObject.SelectToken('return').ToString;
    //Read and Parse JSONArray CLEAR(JSONManagement); CLEAR(JObject); JSONManagement.InitializeCollection(ArrayString); JSONManagement.GetJsonArray(JSONArray);
    //loop and can do insert FOREACH JObject IN JSONArray DO BEGIN MESSAGE('%1 %2 %3', JObject.GetValue('id') , JObject.GetValue('first_name'), JObject.GetValue('last_name') ); END; Name DataType Subtype Length JSONManagement Codeunit JSON Management JSONArray DotNet Newtonsoft.Json.Linq.JArray.'Newtonsoft.Json, Version=9.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed' JObject DotNet Newtonsoft.Json.Linq.JObject.'Newtonsoft.Json' ArrayString Text


  • mimran Profile Picture
    15 on at

    Thanks, This is helpful.

  • Suggested answer
    NeoMatrix Profile Picture
    256 on at

    Thank for the Reply. It's works perfectly.

  • Suggested answer
    NeoMatrix Profile Picture
    256 on at

    thanks

  • JeroenK Profile Picture
    15 on at

    Hi guys,

    For those who running on 2017 nav. You don't really need the JSON manager codeunit.

    IF lJSONString <> '' THEN
    lJObject := lJObject.Parse(FORMAT(lJSONString));

    lArrayString := lJObject.SelectToken('return').ToString;
    CLEAR(lJObject);
    lJsonArray := lJsonArray.Parse(lArrayString);

    FOREACH lJObject IN lJsonArray DO BEGIN
    MESSAGE('%1 %2 %3', lJObject.GetValue('id'),
    lJObject.GetValue('first_name'),
    lJObject.GetValue('last_name'));
    END;

    lArrayString = Text

    lJSONString = Text

    lJsonArray = DotNet Newtonsoft.Json.Linq.JArray.'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'

    lObject = DotNet Newtonsoft.Json.Linq.JObject.'Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed'

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

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Neeraj Kumar – Community Spotlight

We are honored to recognize Neeraj Kumar as our Community Spotlight honoree for…

Leaderboard > 🔒一 Microsoft Dynamics NAV (Archived)

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans