雨田博客
让斗志、坚持、自信成为习惯

导航

 
[DllImport("OpenNetStream.dll")] 
public static extern int OpenSDK_Data_GetDevList(IntPtr szAccessToken, int iPageStart, int iPageSize,
                                                         ref IntPtr pBuf, ref int iLength);

//其中pBuf参数,为返回的一个byte[]数据,现在要将其转换为byte[],然后在转换为string

 

int size = 1024;
byte[] managedArray = new byte[size];
Marshal.Copy(pBuf, managedArray, 0, size);

//获得string类型
string json = System.Text.Encoding.Default.GetString(managedArray);

参考:http://stackoverflow.com/questions/5486938/c-sharp-how-to-get-byte-from-intptr

https://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshal.copy.aspx

posted on 2016-03-16 17:32  张雨田  阅读(9992)  评论(0)    收藏  举报