PHP JSON响应没有验证

时间:2015-02-10 09:45:46

标签: php json

我正在尝试缓存JSON API响应,因此我不会经常访问Meetup API服务器:

header('Content-Type: application/json');
$cURL = curl_init();
curl_setopt($cURL, CURLOPT_URL, "https://api.meetup.com/2/events?back&fields=event_hosts&group_urlname=$group_urlname&page=999&api&key=$api_key");
curl_setopt($cURL, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($cURL, CURLOPT_SSL_VERIFYPEER, 0);
echo json_encode(json_decode(curl_exec($cURL)))

这输出JSON很好,但它没有验证。 JSON代码如下所示:

{"results":[{"status":"upcoming","visibility":"public","maybe_rsvp_count":0,"venue":{"id":20151862,"lon":-0.080918,"repinned":false,"name":"ISTD2 DANCE STUDIOS, ","address_1":"346 Old Street, EC1V 9NQ ","lat":51.526608,"country":"gb","city":"London"},"event_hosts":[{"member_name":"Ram Maree","member_id":12204723},{"member_name":"Jon","member_id":62369612},{"member_name":"David Murray","member_id":126425602}],"fee":{"amount":5,"description":"per person","label":"Price","required":"0","accepts":"paypal","currency":"GBP"},"id":"220172436","utc_offset":0,"duration":5400000,"time":1423594800000,"waitlist_count":0,"updated":1423429374000,"yes_rsvp_count":20,"created":1422568871000,"event_url":"http:\/\/www.meetup.com\/Public-Speaking-for-Dummies\/events\/220172436\/" 

当我浏览http://jsonlint.com/代码时,代码无法验证。我收到一个Parse错误,如:

  

第420行解析错误:..." event_url":" http://www.meetup   ----------------------- ^期待' STRING',' NUMBER',' NULL&#39 ;,' TRUE',' FALSE',' {',' ['

有没有人知道如何使用PHP以正确的格式返回JSON API?

此外,当我直接访问JSON api调用时,JSON会进行验证。所以一旦PHP涉及到问题就会出现问题。

0 个答案:

没有答案