How can I pass value from C/AL type into JSON?

undy0602undy0602 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

Best Answer

Answers

  • CaponeCapone Member Posts: 125
    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.com
  • EvREvR Member Posts: 178
    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.
  • undy0602undy0602 Member Posts: 67
    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,
    Undy
  • EvREvR Member Posts: 178
    The response you get from your API is (I assume) a JSON string.
    Which is basically just another notation. You can simple deserialize in NAV using the Newtonsoft.Json assembly that comes included with NAV.

    fh2c00vgmiav.png

    t504b891ydya.png
  • undy0602undy0602 Member Posts: 67
    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,
    Undy
  • undy0602undy0602 Member Posts: 67
    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,
    Undy
  • undy0602undy0602 Member Posts: 67
    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,
    Undy
  • undy0602undy0602 Member Posts: 67
    Dear EvR,
    I`ve been waiting for your reply for this help :)

    Regards,
    Undy
  • gbengagbenga Member Posts: 1
    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.
Sign In or Register to comment.