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;