How to capture values in a JSON String.

shanabeywicrema
Member Posts: 53
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*"
},
],
Thanks
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*"
},
],
Thanks
0
Best Answers
-
In Dynamics NAV 2013 there is not functions to deal with JSON but you can get the ones in NAV 2016 and adapt it to NAV 2013.
You need to get the add-in Newtonsoft.Json from the NAV 2016 version too and copy in the add-in folder of the NAV 2013 version.
These are the objects.Type ID Name Table 1235 XML Structure Codeunit 1235 XML Buffer Writer Codeunit 1237 Get Json Structure
And here there is a link to a zip file with the objects in NAV 2013, a report using the JSON data you posted, a file with the jason data and the add-in in the Json folder.
https://www.dropbox.com/s/9tehsgomd5ms7o8/json_datos_2013.zip?dl=1
Regards.
5 -
Hello @shanabeywicrema ,
Did you copy the Json fiolder in the zip file inside the Add-ins folder of the service ?
Usually this:C:\Program Files\Microsoft Dynamics NAV\70\Service\Add-ins
Regards5 -
Hello @shanabeywicrema ,
The problem is that your Json data don't have a root item
Maybe the best way is to wrap the Request.responseText with a root Item, something like this:GenerateStructureFromText('{data:{' + Request.responseText +'}',TempXMLBuf,True);
Regards5 -
Sorry but you need double quotes for the new root item
GenerateStructureFromText('{"data":{' + Request.responseText +'}',TempXMLBuf,True);
5
Answers
-
In Dynamics NAV 2013 there is not functions to deal with JSON but you can get the ones in NAV 2016 and adapt it to NAV 2013.
You need to get the add-in Newtonsoft.Json from the NAV 2016 version too and copy in the add-in folder of the NAV 2013 version.
These are the objects.Type ID Name Table 1235 XML Structure Codeunit 1235 XML Buffer Writer Codeunit 1237 Get Json Structure
And here there is a link to a zip file with the objects in NAV 2013, a report using the JSON data you posted, a file with the jason data and the add-in in the Json folder.
https://www.dropbox.com/s/9tehsgomd5ms7o8/json_datos_2013.zip?dl=1
Regards.
5 -
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=7.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, type Newtonsoft.Json.JsonConvert.
OK
0 -
Hello @shanabeywicrema ,
Did you copy the Json fiolder in the zip file inside the Add-ins folder of the service ?
Usually this:C:\Program Files\Microsoft Dynamics NAV\70\Service\Add-ins
Regards5 -
I just copied into program 86. Not it is working, Thank you so much my problem has solved.0
-
Hi, Is there any way that we can pass text or bigtext instead of file ?0
-
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.
Regards.0 -
[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!0 -
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.
OK
0 -
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 ?
Regards.0 -
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;
Request.open('GET',MySetup."APIEndpoint"+'documents/order/'+ID,FALSE,'','');
Request.setRequestHeader('Content-Type',ContentType);
Request.setRequestHeader('sessionId',UserSessionID);
Request.send('');
IF Request.status = 200 THEN BEGIN
GenerateStructureFromText(Request.responseText,TempXMLBuf,True);
END;
I use message to check the response text. I am getting the data.0 -
Hello @shanabeywicrema ,
The problem is that your Json data don't have a root item
Maybe the best way is to wrap the Request.responseText with a root Item, something like this:GenerateStructureFromText('{data:{' + Request.responseText +'}',TempXMLBuf,True);
Regards5 -
Sorry but you need double quotes for the new root item
GenerateStructureFromText('{"data":{' + Request.responseText +'}',TempXMLBuf,True);
5 -
Sorry again @shanabeywicrema,
The right call is this one:GenerateStructureFromText('{"data":' + Request.responseText +'}',TempXMLBuf,True);
You need to remove the second curly brace.
Regards.0 -
0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.6K Microsoft Dynamics NAV
- 18.7K NAV Three Tier
- 38.4K NAV/Navision Classic Client
- 3.6K Navision Attain
- 2.4K Navision Financials
- 116 Navision DOS
- 851 Navision e-Commerce
- 1K NAV Tips & Tricks
- 772 NAV Dutch speaking only
- 617 NAV Courses, Exams & Certification
- 2K Microsoft Dynamics-Other
- 1.5K Dynamics AX
- 320 Dynamics CRM
- 111 Dynamics GP
- 10 Dynamics SL
- 1.5K Other
- 990 SQL General
- 383 SQL Performance
- 34 SQL Tips & Tricks
- 35 Design Patterns (General & Best Practices)
- 1 Architectural Patterns
- 10 Design Patterns
- 5 Implementation Patterns
- 53 3rd Party Products, Services & Events
- 1.6K General
- 1.1K General Chat
- 1.6K Website
- 83 Testing
- 1.2K Download section
- 23 How Tos section
- 252 Feedback
- 12 NAV TechDays 2013 Sessions
- 13 NAV TechDays 2012 Sessions