Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Json 在Google Translate API中使用以下输入格式的优势是什么_Json_Api Design_Google Translate - Fatal编程技术网

Json 在Google Translate API中使用以下输入格式的优势是什么

Json 在Google Translate API中使用以下输入格式的优势是什么,json,api-design,google-translate,Json,Api Design,Google Translate,Google Translate API现在需要翻译多个输入,如下所示: --data "{'q': 'Hello world','q': 'My name is Jeff','target': 'de'}" 他们可以使用如下数组,而不是像上面那样为“q”使用多个条目: --data "{'q':['Hello world','My name is Jeff'],'target': 'de'}" 第1种格式的优点是什么?我已经测试了两种版本,得到了相同的结果,消息被翻译成德语 请尝试以下代

Google Translate API现在需要翻译多个输入,如下所示:

--data "{'q': 'Hello world','q': 'My name is Jeff','target': 'de'}"
他们可以使用如下数组,而不是像上面那样为“q”使用多个条目:

 --data "{'q':['Hello world','My name is Jeff'],'target': 'de'}"

第1种格式的优点是什么?

我已经测试了两种版本,得到了相同的结果,消息被翻译成德语

请尝试以下代码:

curl -s -X POST -H "Content-Type: application/json" \   
    -H "Authorization: Bearer "$(gcloud auth print-access-token) \ 
    --data "{'q':['Hello world','My name is Jeff'],'target': 'de'}" \
"https://translation.googleapis.com/language/translate/v2"
您将得到以下响应:

{
  "data": {
    "translations": [
      {
        "translatedText": "Hallo Welt",
        "detectedSourceLanguage": "en"
      },
      {
        "translatedText": "Mein Name ist Jeff",
        "detectedSourceLanguage": "en"
      }
    ]
  }
}
您可能需要身份验证凭据才能工作,请按照步骤添加这些凭据,然后测试上述代码