当前位置: 动力学知识库 > 问答 > 编程问答 >

microsoft dynamics - Convert from C/AL object to JSON

问题描述:

As per title, is there any way to convert from C/AL object to JSON object? If I'm not mistaken, some of the data types in C/AL can be converted straight to .NET object (string, int, etc) but I'm not sure which types are / are not.

I'm looking to transfer tables and query type variables to managed codes using JSON. Do I need to construct the whole JSON and serialize it before sending it over? Or is there anything simpler way?

I'm looking if there's any way to do something like this:

JsonConvert.Serialize(MyTableVariable);

JsonConvert.Serialize(MyQueryVariable);

网友答案:

There is no standard way to convert record/query to json. Moreover you would never want to see all record's fields in json. Most probably you need only small subset of the fields. You need to create json manually.

You can use RecordRef/FieldRef types to iterate through fields of the record and export them into json fields. If you do this it will be universal for any record variable in the system. Not sure you can do the same with queries though. And you will need to handle each document individually.

Alternatively you can create an XMLPort for each designated record/document/query and use it to export data to xml first and then convert xml to json. But there may be issues with conversion itself and Nav's ports inflexibility (if you need conplex json structure).

分享给朋友:
您可能感兴趣的文章:
随机阅读: