I receive dynamic JSON in my web api post request.
[HttpPost("receive")]
public async Task<IActionResult> ReceiveJson([FromBody] JsonDocument document)
One of my JSON elements is a binary array:
"attachments": [
{
"content": [
255,
216,
...
128,
70
]
}
I am unable to read that array into anything really.
I can get it as a JsonElement and see that it is ValueKind Array:
ok = attachment.TryGetProperty("content", out JsonElement attachmentContent);
string attachmentContentType = attachmentContent.ValueKind.ToString();
//gives Array
But how do I get it itto a byte[]?
2
Answers
The following code is a custom JSON converter for byte array:
As an example:
Following code retrieves byte[] from the JsonElement: