Hi
In C# you would use this code to populate a ByteArray from a String:
string postData = "xml content";
byte[] byteArray = Encoding.UTF8.GetBytes (postData);
How to do it in X++?
Thanks, Jan
*This post is locked for comments
AX4 doesn't support arrays in that fashion. You can loosely type a variable as a byte array using CLRObject.
The following code works.
CLRObject byteArray;
System.Text.Encoding encoding;
str string;
int byte, i, arrayLength;
;
string = "Sample string";
encoding = System.Text.Encoding::get_UTF8();
byteArray = encoding.GetBytes(string);
arrayLength = byteArray.get_Length();
for (i = 0; i < arrayLength; i++)
{
byte = byteArray.GetValue(i);
info(strfmt("%1", byte));
}
how to use it in ax 4 ? .. i got error when using system.byte[] ...
Marking as suggested answer
Of course you can it direct, until you have to go back to AX datatype, than you have to use CLRInterop for conversion. There is the point where not all types can be handeld in AX.
The very direct approach is to do the same in AX (2009):
str postData = "xml content";
System.Byte[] byteArray;
System.Text.Encoding encodingUTF8;
;
encodingUTF8 = System.Text.Encoding::get_UTF8();
byteArray = encodingUTF8.GetBytes(postData);
It depends on what for the array of bytes is required.
Hi
After playing around with ClrInterop what did not work we used .NET classes and made a reference in AOT.
Regards
Hi jan,
Were u able to solve the above issue. can u guide me on this.
thnx
KrPr
Mohamed Amine Mahmoudi
100
Super User 2025 Season 1
Community Member
48
Zain Mehmood
6
Moderator