小编Sob*_*oby的帖子

如何将 utf8 转换为 std::string?

我正在处理这个代码,它接收一个 cpprest sdk 响应,其中包含一个 base64_encoded 有效负载,它是一个 json。这是我的代码片段:

typedef std::wstring string_t; //defined in basic_types.h in cpprest lib
    void demo() {
        http_response response; 
        //code to handle respose ...
        json::value output= response.extract_json();
        string_t payload = output.at(L"payload").as_string();
        vector<unsigned char> base64_encoded_payload = conversions::from_base64(payload);
        std::string utf8_payload(base64_encoded_payload.begin(), base64_encoded_payload.end()); //in debugger I see the Japanese chars are garbled.
        string_t utf16_payload = utf8_to_utf16(utf8_payload); //in debugger I see the Japanese chars are good here
        //then I need to process the utf8_payload which is an xml.
        //I have an API available …
Run Code Online (Sandbox Code Playgroud)

c++ unicode utf-16 cjk cpprest-sdk

2
推荐指数
1
解决办法
3681
查看次数

标签 统计

c++ ×1

cjk ×1

cpprest-sdk ×1

unicode ×1

utf-16 ×1