如何将byte [100]转换为guid [英] how to convert byte[100] to guid

查看:167
本文介绍了如何将byte [100]转换为guid的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到的服务响应是 byte [100] 如何将其转换为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);


推荐答案

有一个 Guid构造器,该构造器允许您从16个元素的字节数组中初始化Guid。因此,您必须首先将100个元素数组中的16个元素提取到一个新元素中,然后初始化Guid。当然,要从100个元素数组中提取哪个16个元素。

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.

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

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));

这篇关于如何将byte [100]转换为guid的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆