0

我在 Tizen 中开发了一个用于 Http 请求和响应的应用程序。我能够成功发布并获得回复。(检查身体长度)。我得到的响应在 ByteBuffer 中。

ByteBuffer* pBuffer = pHttpResponse->ReadBodyN();

我在类型转换方面有点差。我希望将此 ByteBuffer 转换为字符串,以便我可以在标签中进行设置。

4

1 回答 1

1

数据是以ByteBuffer零结尾的 ASCII 码吗?在这种情况下,您可以像这样创建字符串:

String str((const char*)(byteBuf.GetPointer()));

否则,只要您知道编码是什么,您就可以ByteBuffer使用Tizen::Text::Encoding解码。例如:

// Construct some test data. In your case the buffer would come
// as a HTTP response.
char chars[] = "\xE5\xE6\xF6";  // æåø in ISO-8859-1
ByteBuffer byteBuf;
byteBuf.Construct((byte*)chars, 0, 3, 3);

Encoding* pEnc = Encoding::GetEncodingN(L"ISO-8859-1");
String str;
pEnc->GetString(byteBuf, 0, byteBuf.GetRemaining(), str);

Label *pLabel = static_cast<Label*>(GetControl(IDC_LABEL1));
pLabel->SetText(str);
于 2013-06-18T06:07:28.777 回答