本文介绍了Pinterest API - 纯 json 响应?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我向 Pinterest 的 API 发出了一个简单的 HTTP 请求来获取链接的数量:

So I made a simple HTTP request to Pinterest's API to get the count of a link:

$this->load->library('rest');
$this->rest->initialize(array('server' => 'http://api.pinterest.com/'));
$return_data = $this->rest->get('v1/urls/count.json?callback=&url=' . $link);

我得到的回应是:

receiveCount({"count": 5743, "url": "http://google.com"})

您可以在这里亲自尝试.

我不想要回调,我尝试设置 callback= 但括号仍然存在,所以我无法通过 json_decode 解析它.

I don't want the callback and I tried setting callback= but the parenthesis are still present so I can't parse it via json_decode.

是否有更好的方法来获得纯 json 响应而不必自己用字符串替换括号?

Is there a better way of getting a pure json response without having to string replace the parenthesis myself?

推荐答案

Pintrest API 目前正在开发中,尚未准备好供公众使用;他们不久前删除了自己的文档.但是,对于 API 的 v2,Bolt 上有一个缓存.

The Pintrest API is currently in development and is not ready for public use; they removed their own documentation a while ago. There is however a cache on Bolt for v2 of the API.

现在我只会对响应做一个正则表达式,例如

For now I would just do a regex on the response such as

$return_data = preg_replace('/^receiveCount\((.*)\)$/', "\\1", $return_data);

然后json_decode那个.

这篇关于Pinterest API - 纯 json 响应?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 20:08