作者:kas8288408 | 来源:互联网 | 2023-10-12 09:15
参考文章
func handleResponse(resp *http.Response) (string, error) {
respBytes, err := ioutil.ReadAll(resp.Body)
defer resp.Body.Close()
if err != nil {
fmt.Println(err.Error())
return "", err
}
str := (*string)(unsafe.Pointer(&respBytes))
result := unicode2utf8(*str)
fmt.Println(result)
return result, nil
}
func unicode2utf8(source string) string {
var res = []string{""}
sUnicode := strings.Split(source, "\\u")
var context = ""
for _, v := range sUnicode {
var additional = ""
if len(v) < 1 {
continue
}
if len(v) > 4 {
rs := []rune(v)
v = string(rs[:4])
additional = string(rs[4:])
}
temp, err := strconv.ParseInt(v, 16, 32)
if err != nil {
context = v
}
context = fmt.Sprintf("%c", temp)
context = additional
}
res = append(res, context)
return strings.Join(res, "")
}