【问题标题】:Converting JSON in url into a string将 url 中的 JSON 转换为字符串
【发布时间】:2012-08-17 10:11:58
【问题描述】:

http://api-public.addthis.com/url/shares.json?url=http://google.com

我需要以 php 字符串的形式获取共享数量。 (回声)

有什么简单的方法吗?

【问题讨论】:

  • json_decode() 就是你要找的东西
  • 这是给你的一个班轮echo array_shift(json_decode(file_get_contents("http://api-public.addthis.com/url/shares.json?url=http://google.com"), true));

标签: php json string echo


【解决方案1】:
$ret = json_decode(file_get_contents('http://api-public.addthis.com/url/shares.json?url=http://google.com'), true);
echo $ret['shares'];

【讨论】:

  • 为什么输出的是1404114041而不是14041?再次感谢。
  • 对不起,这是我代码中的错误部分。这个答案非常有效。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-06-28
  • 2018-03-08
  • 1970-01-01
  • 2012-10-06
  • 1970-01-01
相关资源
最近更新 更多