Dear everyone,
i have a problem to loop through nested JObjects within the Json Management
{
"entries": {
"10000": {
"product": "A",
"pricePerUnit": 5.68,
},
"20000": {
"product": "B",
"pricePerUnit": 5.83,
},
"30000": {
"product": "A",
"pricePerUnit": 5.53,
}
},
"currency": "EUR"
}
At the moment we used the following code to run through the JObject, but it is not working:
JSONManagement.InitializeObject(Json);
JSONManagement.GetJSONObject(JObject);
JSONManagement.GetArrayPropertyValueFromJObjectByName(JObject,'Customer',JsonArray);
FOR Index := 1 TO JsonArray.Count DO BEGIN
JCustObject := JsonArray.Item(Index - 1);
JSONManagement.GetStringPropertyValueFromJObjectByName(JCustObject,'No',Value);
TempCustomer."No." := Value;
TempCustomer.INSERT;
END;
I've tried to use the Jobject.GetValue command but I'll always recieve an error message
How can i correctly loop through the Jobject with the Json Management.
Answers
I need some idea to create the above JSON file thru C/AL. Do you have some time to share ?
The bellow JSON could be made with a code like (keep in mind it's not tested!) this:
Here:
MainJSON, EntryJSON and SubEntryJSON are of subtype "Newtonsoft.Json.Linq.JObject.'Newtonsoft.Json'"
EntriesJSONArray of subtype "Newtonsoft.Json.Linq.JArray.'Newtonsoft.Json'"
And JSONMgt is Codeunit 5459 - JSON Management
Thanks a lot.
is there a way for this nested json but for cloud environment?
Sure there is, here is just an example, I didn't go through records like @ShaiHulud, but I believe you get the idea: