I'm using a post method to post Inventory data to an Https site. I was able to create a json string that looks like this example:
{"CustomerKey": "112221124545412","partCode": "Items-1","Description":"Chips"}
however I need the string look like the following:
{
"parts": "[\r\n {\r\n \"CustomerKey\": \"e3704b8b-a09a-4143-8bb5-81bce8d5af43\",\r\n \"PartCode\": \"Part 2\",\r\n \"Description\": \"Part Description\",\r\n \"AlternateDescription\": \"\",\r\n \"UnitOfMeasure\": \"Each\",\r\n \"EffectiveDate\": null,\r\n \"ExpiryDate\": null,\r\n \"ThresholdQuantity\": 10,\r\n \"Location\": \"4\",\r\n \"Certified\": false,\r\n \"Taxable\": false,\r\n \"UnitPrice\": 0,\r\n \"Quantity\": 0,\r\n \"OrderedbutNotReceived\": 0\r\n },\r\n {\r\n \"CustomerKey\": \"e3704b8b-a09a-4143-8bb5-81bce8d5af43\",\r\n \"PartCode\": \"Part 3\",\r\n \"Description\": \"Part Description\",\r\n \"AlternateDescription\": \"\",\r\n \"UnitOfMeasure\": \"Each\",\r\n \"EffectiveDate\": null,\r\n \"ExpiryDate\": null,\r\n \"ThresholdQuantity\": 10,\r\n \"Location\": \"4\",\r\n \"Certified\": false,\r\n \"Taxable\": false,\r\n \"UnitPrice\": 0,\r\n \"Quantity\": 0,\r\n \"OrderedbutNotReceived\": 0\r\n }\r\n ]"
}
I'm guessing I need to convert the Json object to an Array list!! is that true and how would I do that?
Thanks for the help
*This post is locked for comments
Hello evbitas,
Hope you have achieved your format.
This is the format which I am trying to achieve in NAV 2016. Can you please guide to achieve this and how did you achieve?
{
"bill": {
"DocType": "INV",
"DocNo": "104003",
"DocDate": "08/02/2019",
"ItemList": [
{
"ProductName": "TS1070I",
"ProductDesc": "Manuafor eakers",
"HsnCode": "85044090",
"Quantity": "4",
},
{
"ProductName": "TS1080I",
"ProductDesc": "Manuafor eakers",
"HsnCode": "85044090",
"Quantity": "4",
}
]
}
}
Thanks,
Thanks Andrey for your help. Your answers helped me a lot.
Thanks again..
All objects are "Newtonsoft.Json.Linq.JObject"
Array is Newtonsoft.Json.Linq.JArray
By the way - I recommend you to take Codeunit 5459 JSON Management from NAV2018 and import it to your NAV2015 - it contains all the needed functions.
Thanks Andrey for the Info you provided. Yes I'm using Newtonsoft JSON dll.
I'll try your solution and let you know.. Do you know what DotNet objects you used for JsonLineObject, JsonMainObject. , JsonArray ?
Thanks again
Hi!
I don't know, how you create JSON in NAV 2015 (perhaps it's Newtonsoft JSON dll), but in business central process is next:
1. You create Array element (as Json object) :
JsonLineObject.Add('CustomerKey', '112221124545412');
.......
JsonLineObject.Add('OrderedbutNotReceived', '123124');
2. You add element to Array :
JsonArray.Add(JsonLineObject);
(probably you will do step 1 and 2 in REPEAT cycle)
3. You create Main JsonObject with your array:
JsonMainObject.Add('parts', JsonArray.AsToken.AsArray());
4. You send JsonMainObject to API.
Stay up to date on forum activity by subscribing. You can also customize your in-app and email Notification settings across all subscriptions.
André Arnaud de Cal... 291,240 Super User 2024 Season 2
Martin Dráb 230,149 Most Valuable Professional
nmaenpaa 101,156