这段代码在反应原生中运行,我无法得到正确的响应。
let url =
'https://translate.googleapis.com/translate_a/single?client=gtx&sl=hi&tl=en&dt=t&q=नमस्ते';
fetch(url, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: null,
})
.then((response) => response.json())
.then((responseJson) => {
console.log('responseJson: ', responseJson);
// response: [[["¥ ¥ ¥ à¤¤à ¥ ‡","नमसॠते",null,null,3]],null,"hi"]
})
.catch((error) => {
console.error(error);
});
我还使用encodeURI来转换URL,对我不起作用。
请在第一行将":"更改为"="!!
let url = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=hi&tl=en&dt=t&q=नमस्ते"