php - 转换 json 中的特殊字符串答案或获取数据 PHP 的访问权限
问题描述
我有这个:-
$str = 'hello';
$url = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=fr&dt=t&q=" . $str;
$R=file_get_contents($url);
print($R);
我得到:-
[[["Bonjour","hello",null,null,1] ] ,null,"en",null,null,null,1.0,[] ,[["en"] ,null,[1.0] ,["en"] ] ]
你能帮我访问'Bonjour'
和'en'
吗?
它是一个字符串,我正在尝试解码、解码等,但没有任何工作可以让事情变得正常。先感谢您
解决方案
您收到的数据是 json 格式,因此您应该对其进行解码。
$str = 'hello';
$url = "https://translate.googleapis.com/translate_a/single?client=gtx&sl=auto&tl=fr&dt=t&q=" . $str;
$result = file_get_contents($url);
$data = json_decode($result);
//print_r($data);
$bonjour = $data[0][0][0];
$en = $data[2];
echo $bonjour . ' ' . $en;
推荐阅读
- epplus - EPPLus - 从 C# 中仅打开 Excel 文件的前 1000 行
- json - 如何使用 JSONPath 获取 JSON 数组的长度?
- django - Linkedin-api 此资源在 v1 API 下不再可用
- r - 如何将一列转换为R中的行?
- java - hibernate 5 - 无法获取当前线程的事务同步会话;
- php - 缺少来自 PHP/Apache2 的响应的 CORS 标头
- html - 无法打印 Ionic 3 页面的全部内容
- c++ - 从匿名命名空间中分配值映射抛出 std::bad_alloc
- .htaccess - 嗨,我想知道 .htaccess 文件中 (.*) 和 ([a-zA-Z0-9]+) 之间的区别是什么
- snowflake-cloud-data-platform - 如何将整数数组转换为行?