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 :
Small and medium business | Business Central, N...
Suggested Answer

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

(0) ShareShare
ReportReport
Posted on by

Dear Experts,

I am looking to iterate JSON Array in 2013R2.

Followed this Link to iterate in 2018 but with 2013R2 on writing it in this manner is giving the whole Jobject and on clear as mentioned it does not find the property name and throws an error of Parameter type.

It keeps on Iterating the same data of token return as foreach is not supported in 2013r2

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",
}

}

https://community.dynamics.com/nav/f/microsoft-dynamics-nav-forum/350906/how-to-iterate-over-json-array-in-navison-2018-using-c-al/938056

Sample Code Changes:

 UPLOADINTOSTREAM('Import', '', 'All Files (*.*)|*.*',FileName,Instream1) ;

InStream1.READTEXT(TextValue);
WHILE NOT InStream1.EOS DO BEGIN
  InStream1.READTEXT(ContentLine);
 TextValue  = LineSeperator   ContentLine;
END;


JSonString:=TextValue;


//Copied Jsonmanagement from 2016
///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 
    FOR i :=0 TO JSONArray.Count-1 DO BEGIN  //NAV2013R2
    JSONArray.Item(i,JObject);                //NAV2013R2
  
    MESSAGE('%1 %2 %3', JObject.GetValue('id') ,
                        JObject.GetValue('first_name'),
                        JObject.GetValue('last_name')
               );
END;
I have the same question (0)
  • Suggested answer
    THE Italian Profile Picture
    on at

    If you cannot make it with .NET interop as such then you have to create your own assembly, e.g with C#, and then deploy this assembly and call it from the client.

    NAV 2013, 2013 R2, 2015 are already out of mainstream support. You might try to deploy the latest platform for NAV 2013 R2 to double check if this is resolved. If not, then you have the value of upgrade at fingertips. 

    Keep in mind that if you move to AL based version, you already have out of the box JSON objects handling by the runtime itself. See 

    JsonObject Data Type - Business Central | Microsoft Docs

  • Suggested answer
    Community Member Profile Picture
    on at

    community.dynamics.com/.../1122826

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 > Small and medium business | Business Central, NAV, RMS

#1
OussamaSabbouh Profile Picture

OussamaSabbouh 2,135

#2
YUN ZHU Profile Picture

YUN ZHU 733 Super User 2025 Season 2

#3
Sumit Singh Profile Picture

Sumit Singh 612

Last 30 days Overall leaderboard

Featured topics

Product updates

Dynamics 365 release plans