How can I pass value from C/AL type into JSON?
undy0602
Member Posts: 67
Hello all,
I have external assembley that has Json ustring data. I have to pass value between Json .NET type and C/AL type?
Are below converts are same?
1. Json .NET into C/AL
C/AL into Json .NET
2. std::string into std::wstring
std::wstring into std::string
How can I pass value between Json and C/AL?
Regards,
Undy
I have external assembley that has Json ustring data. I have to pass value between Json .NET type and C/AL type?
Are below converts are same?
1. Json .NET into C/AL
C/AL into Json .NET
2. std::string into std::wstring
std::wstring into std::string
How can I pass value between Json and C/AL?
Regards,
Undy
0
Best Answer
-
I would create a matching serializable class with all the properties you need. The SerializeObject method expects an object that it can serialize. So don't feed it with a string but with an actual class.
My class would look like this:
First loop all the stock entries you need, creating new instances of a Stock class and add them to a generic list (System.Collections.Generic.List`1.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') one by one.
When you're done looping, instantiate an object of your VATEntry class, with the list of 'Stocks'.
5
Answers
-
I can't answer your question but maybe this session can answer your question?
It gives a couple of examples on how to use JSON in NAV.
mibuso.com/downloads/nav-techdays-2015-connecting-to-the-outside-world-how-to-get-the-best-out-of-web-services-movie
Or check out Kaufmans blog about this:
kauffmann.nl/index.php/2015/11/26/nav-techdays-2015-the-web-service-examples/Hello IT, have you tried to turn it off and on?
Have you checked the cables?
Have you released the filters?
http://www.navfreak.com0 -
What do you mean by 'pass values'? JSON is just a serialization format.
Do you want to deserialize a JSON string to an object in C/AL? If so, you would have to create .NET classes and use those to serialize/deserialize. Then you can use those objects to transfer data to NAV objects.0 -
Thanks EvR,
I have external assembley and it has JSON type functions. I have to get values into this functions and return some values from these functions.
Assembley.Put(amount,name) :=value from NAV
Assembley.Send(id, No) <-return values from API service
I dont any experience with .NET especially JSON so How can I use serialize/deserialize?
Regards,
Undy0 -
Thank you very much EvR,
Your advise is helpful to me so much. This example is Json string->.NET assembley. But I have to put values to Json string from NAV string. NAV string ->Json .NET assembley
Can I use JSonConvert.SerializeObject?
Regards,
Undy0 -
My "BridgePos.Class1" assembley has put() function and it has below json string fields.
put(ustring)
{"amount": String, "vat": String, "cashAmount": String, "nonCashAmount": String,
"stocks": [{ "code": String, "name": String,"measureUnit": String, "qty": String,}],
I want to pass value into this put() function from C/AL (vat entries).
I tried on below example:
MyString:='123.45';
BridgePos:=BridgePos.Class1;
Type:=BridgePos.GetType();
JsonSerializerSettings:=JsonSerializerSettings.JsonSerializerSettings();
Result:=JsonConvert.SerializeObject(MyJsonString,Type,JsonSerializerSettings);
MESSAGE('BridgePos result %1',BridgePos.put(Result));
But it appears wrong type data and cant pass value
Regards,
Undy0 -
I would create a matching serializable class with all the properties you need. The SerializeObject method expects an object that it can serialize. So don't feed it with a string but with an actual class.
My class would look like this:
First loop all the stock entries you need, creating new instances of a Stock class and add them to a generic list (System.Collections.Generic.List`1.'mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089') one by one.
When you're done looping, instantiate an object of your VATEntry class, with the list of 'Stocks'.
5 -
Thank you very much for your hard working help EvR,
It helps me alot.
There is one issue left. How to instantiate an object of VATEntry class, with list of Stocks?
Best Regards,
Undy0 -
Dear EvR,
I`ve been waiting for your reply for this help
Regards,
Undy0 -
Hi Undy0602,
I need your help on these where you able to finish the project as I have similar thing and I would want to know how you were able to work it out.0
Categories
- All Categories
- 73 General
- 73 Announcements
- 66.7K Microsoft Dynamics NAV
- 18.8K 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
- 328 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



