簡體   English   中英

使用nodeFetch在JSON API響應中正確顯示特殊字符

[英]Correctly display special characters in JSON API response using nodeFetch

我有一個通過HTTP與RESTful API通信的反應應用程序。 API返回一個可能包含特殊字符的JSON響應主體。

示例響應可能如下所示:

{
    "name": "Property One",
    "description": "Res Thick Film 0805 49.9 Ohm 1% 0.25W(1/4W) ±100ppm/°C Pad SMD Automotive T/R",
    ...
}

所討論的特殊字符是(但不限於)±和°。

我使用nodeFetch執行請求, nodeFetch所示:

nodeFetch(url, { method: 'GET', headers }).then(response => response.json());

如果我在使用response.json()反序列化后觀察對象,則description屬性現在如下所示:

"Res Thick Film 0805 49.9 Ohm 1% 0.25W(1/4W) �100ppm/�C Pad SMD Automotive T/R"

如何阻止特殊字符替換為 ?

你也可以看一下這個問題,可能cskau-g repost應該可以幫到你https://github.com/dart-lang/http/issues/175

我認為問題是編碼為utf-8,內容類型必須設置為text / html

您可能應該設置標題: Content-Typetext/html; charset=utf8 text/html; charset=utf8 nodeFetch支持開箱即用的UTF-8

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM