【问题标题】:How to get information on php telegram bots from JSON on the site如何从网站上的 JSON 获取有关 php 电报机器人的信息
【发布时间】:2019-07-12 03:19:47
【问题描述】:

我想在这个网站上接收应用程序。所以船需要得到乌兹别克斯坦这个词。但它不起作用!

$json = file_get_contents("https://restcountries.eu/rest/v2/name/uzbekistan");
$json = json_decode ($json);
$res = $json->name;
if(isset($text1)){
  bot('sendmessage',[
    'chat_id'=>$chat_id,
    'text'=>"$res" //there is 'Uzbekistan'
  ]);
}

【问题讨论】:

  • 什么是$text1
  • 输入文字@text1

标签: php json bots telegram


【解决方案1】:

从以下位置更改您的代码:

$json = json_decode ($json);
$res = $json->name;

收件人:

$json1 = json_decode($json, true);
$res = $json1[0]['name'];

你会得到名字,因为你在 index[0] 中输入数组,第一个参数是 ['name']。

【讨论】:

  • 成功了。但是还有另一个问题。如何从这里获取“TopLevelDomain”?
  • 这很容易。你只需要遵循模式。在这种情况下,如果您想访问“TopLevelDomain”,请执行 $json1[0]['topLevelDomain'][0] 。你必须放 [0],因为那是一个数组,你去他的索引的第一个位置是 [0],瞧
猜你喜欢
  • 2018-01-12
  • 1970-01-01
  • 1970-01-01
  • 2015-09-22
  • 2022-06-10
  • 1970-01-01
  • 1970-01-01
  • 2017-09-24
  • 2016-09-08
相关资源
最近更新 更多