字节串到字节数组c#

Moe*_*eck 2 c# byte json

在我的Web应用程序中,我连接到Web服务.在我的Web服务中,它有一个根据路径获取报告字节的方​​法:

public byte[] GetDocument(string path)
{
   byte[] bytes = System.IO.File.ReadAllBytes(path);
   return bytes;
}
Run Code Online (Sandbox Code Playgroud)

现在,当我从我的Web应用程序发出请求时,Web服务给了我一个Json对象,类似于:

{
  "Report":"0M8R4KGxGuEAAAAAAAAAAAAAAAAAAAAAPgADAP7/CQAGAAAAAAAAAAAA
   AAACAAAA3QAAAAAAAAAAEAAA3wAAAAEAAAD+ ... (continues)" 
}
Run Code Online (Sandbox Code Playgroud)

在我的Web应用程序中,我有一个获取Json对象的方法,将"report"放在一个字符串中.然后,Web应用程序有一个方法将字符串解析为字节数组,这不起作用,它抛出一个FormatException:

public byte[] DownloadReport(string id, string fileName)
{
    var fileAsString = _api.DownloadReport(id, fileName);
    byte[] report = fileAsString.Split()
                                .Select(t => byte.Parse(t, NumberStyles.AllowHexSpecifier))
                                .ToArray();
    return report;
}
Run Code Online (Sandbox Code Playgroud)

我也试过这样做:

public byte[] DownloadReport(string id, string fileName)
{
   var fileAsString = _api.DownloadReport(id, fileName);
   byte[] report = Encoding.ASCII.GetBytes(fileAsString);
   return report;
}
Run Code Online (Sandbox Code Playgroud)

这给了我一个.doc文件,其中包含与Json对象完全相同的字符串.

我是从Web服务解析错误的方法,还是我想再次将其转换为字节数组?

Dmy*_*nko 5

public byte[] DownloadReport(string id, string fileName)
    {
        var fileAsString = _api.DownloadReport(id, fileName);
        byte[] report = Convert.FromBase64String(fileAsString);
        return report;
    }
Run Code Online (Sandbox Code Playgroud)