如何将 byte[100] 转换为 guid

发布于 2024-12-03 00:48:22 字数 200 浏览 0 评论 0原文

我收到的服务响应是 byte[100] 我如何将其转换为 guid?

byte[] response = wc.UploadValues(url, "POST", nvc);
string Guid = new Guid(response).ToString();
Response.Write(Guid);

I am receiving a service response which is byte[100] how can i convert it to a guid ?

byte[] response = wc.UploadValues(url, "POST", nvc);
string Guid = new Guid(response).ToString();
Response.Write(Guid);

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

一直在等你来 2024-12-10 00:48:22

有一个Guid构造函数,它允许您从16位初始化Guid -元素字节数组。因此,您必须首先将 100 个元素数组中的 16 个元素提取到一个新数组中,然后初始化 Guid。从 100 个元素的数组中提取哪 16 个元素当然取决于具体情况。

现在我怀疑这里发生的情况是服务器在响应中将 Guid 作为字符串发送。因此,您所要做的就是在转换后解析它使用正确的编码将服务器的响应转换为字符串:

byte[] response = wc.UploadValues(url, "POST", nvc);
var guid = Guid.Parse(Encoding.UTF8.GetString(response));

There is a Guid constructor which allows you to initialize a Guid from a 16-element byte array. So you will have to first extract the 16 elements from your 100 elements array into a new one and then initialize the Guid. Which 16 elements to extract from your 100 elements array would of course depend.

Now I suspect that what happens here is that the server sends the Guid as a string in the response. So all you have to do is parse it after converting the response from the server into a string using the proper encoding:

byte[] response = wc.UploadValues(url, "POST", nvc);
var guid = Guid.Parse(Encoding.UTF8.GetString(response));
从﹋此江山别 2024-12-10 00:48:22

我不完全理解您的代码片段,但 Guid 具有 new (byte[ ])ToByteArray 方法将 Guid 与字节数组相互转换 - 这应该可以解决问题

I don't fully understand your code snippet, but Guid has overloads for new (byte[]) and a ToByteArray Method to transform Guids from and into Byte-Arrays - that should do the trick

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文