如何将unicode字符串从python传递到angular?

2024-09-30 01:21:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个“句子”,我正在从python传递到angular- u'Excellente atenci\xf3n'

它包含一些ASCII字符,当我试图用Angular解析时,该字符会导致解析错误

所以,我试着像“str(句子)”一样传递它,但在python中,它的错误如下-

UnicodeEncodeError: 'ascii' codec can't encode character u'\xf3' in position 16: ordinal not in range(128)

在角度方面,我得到的数据与“Excellente atenci\u00f3n”相同

在误差以下-

SyntaxError: Unexpected token N in JSON at position 224 at JSON.parse (<anonymous>) at XMLHttpRequest.onLoad

另外,我得到的HTTP 200响应如下-

HttpErrorResponse {headers: HttpHeaders, status: 200, statusText: "OK", url: "http://localhost:8080/sentence", ok: false, …}

如何从python中传递正确的句子,以便解析错误不会以角度出现


Tags: injson错误asciiposition字符at句子

热门问题