How to capture values in a JSON String.

shanabeywicremashanabeywicrema Member Posts: 53
edited 2019-02-18 in NAV Three Tier
Hello there,

Is there any way that I can copy JSON value and insert into dynamics nav table,
Here is the sample JSON response. I am doing this in Dynamics NAV 2013. Initially I copied values using SELECTSTR but is there any proper way to do this.
"result": {
"addresses": [
"city": "8888",
"address1": "*******",
"postalCode": "***",
"type": "BT",
"companyName1": "Z*****.",
"recordId": "BT",
"state": "NV",
"locationNumber": "**T",
"dunsNumber": "*T"
"country": "US",
"address2": "********",
"city": "New York",
"address1": "***************,
"postalCode": "**",
"type": "RE",
"companyName1": "***",
"recordId": "RE",
"state": "NY",
"locationNumber": "6*0",
"dunsNumber": "6*"



Best Answers


  • shanabeywicremashanabeywicrema Member Posts: 53
    Hello ftornero ,
    Thank you so much for you effort. It is really worth. After all I got following error. Do you know where I missed. ?

    Microsoft Dynamics NAV

    This message is for C/AL programmers: Cannot create an instance of the following .NET Framework object: assembly Newtonsoft.Json, Version=, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, type Newtonsoft.Json.JsonConvert.
  • shanabeywicremashanabeywicrema Member Posts: 53
    I just copied into program 86. Not it is working, Thank you so much my problem has solved.
  • shanabeywicremashanabeywicrema Member Posts: 53
    Hi, Is there any way that we can pass text or bigtext instead of file ?
  • ftorneroftornero Member Posts: 517
    Yes @shanabeywicrema you need to modify the codeunit 1237 to deal with Text, something like this:


    You should duplicate the previous functions, change the names and parameters and then call the function GenerateStructureFromText with the Text var where is the JSON data.

  • krikikriki Member, Moderator Posts: 9,076
    [Topic moved from 'NAV/Navision Classic Client' forum to 'NAV Three Tier' forum]

    Regards,Alain Krikilion
    No PM,please use the forum. || May the <SOLVED>-attribute be in your title!

  • shanabeywicremashanabeywicrema Member Posts: 53
    Hello @ftornero
    I have done as your code. But When I pass the request, I am getting this error. Could you please guide me where I wrong .

    Microsoft Dynamics NAV

    A call to Newtonsoft.Json.JsonConvert.DeserializeXmlNode failed with this message: JSON root object has multiple properties. The root object must have a single property in order to create a valid XML document. Consider specifing a DeserializeRootElementName. Path 'message', line 1, position 15538.
  • ftorneroftornero Member Posts: 517
    Hello @shanabeywicrema,

    Looks like the problem is with the Json text.

    Could you post how are you filling the text variable with the json data and the real json data ?

  • shanabeywicremashanabeywicrema Member Posts: 53
    Hello @ftornero ,
    I just call the rest web-service and call the relevant function,then I will get the response, Same response I will pass into GenerateStructureFromText

    Request := RequestClass.XMLHTTPRequestClass;'GET',MySetup."APIEndpoint"+'documents/order/'+ID,FALSE,'','');
    IF Request.status = 200 THEN BEGIN

    I use message to check the response text. I am getting the data.
  • ftorneroftornero Member Posts: 517
    Sorry again @shanabeywicrema,

    The right call is this one:
    GenerateStructureFromText('{"data":' + Request.responseText +'}',TempXMLBuf,True);

    You need to remove the second curly brace.

  • rsruchineerajrsruchineeraj Member Posts: 1
    Hi @ftornero,
    It's really working for me. Thanks a lot! :)
Sign In or Register to comment.