此代码在react-native中运行,我无法得到正确的响应。
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转换网址,对我不起作用。
答案 0 :(得分:0)
请在第一行将':'更改为'='!!
let url = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=hi&tl=en&dt=t&q=नमस्ते"