2016-10-05 171 views
-2

我有一个使用Google Calendar API显示即将发生的事件的脚本(来自GitHub)。将JSON响应转换为PHP变量

<script src="https://code.jquery.com/jquery-1.11.3.min.js"></script> 
<script src="format-google-calendar.js"></script> 
<script> 
    formatGoogleCalendar.init({ 
    calendarUrl: 'https://www.googleapis.com/calendar/v3/calendars/[email protected]/events?key=AIzaSyDls1AFdCYUTxYRWpYNUiLwOarKao3WV_c', 
    past: true, 
    upcoming: true, 
    sameDayTimes: true, 
    pastTopN: 20, 
    upcomingTopN: 3, 
    itemsTagName: 'li', 
    upcomingSelector: '#events-upcoming', 
    pastSelector: '#events-past', 
    upcomingHeading: '<h2>Upcoming events</h2>', 
    pastHeading: '<h2>Past events</h2>', 
    format: ['*date*', ': ', '*summary*', ' &mdash; ', '*description*', ' in ', '*location*'] 
    }); 

我想要做的是在每个事件PHP变量的数据的存储区不同的部分,例如:

<?php 
    $date= JSON Date 
    <--! For next event !--> 
    $date2= JSON Date2 
    $date3= JSON Date3 
    ?> 

我只需要3,因为它只会显示3即将发生的事件。

回答

0
<?php 
    $date= file_get_contents('url_for_date'); 
    $dateobj = json_decode($date); 
    $date2= file_get_contents('url_for_date2'); 
    $date2obj = json_decode($date2); 
    $date3= file_get_contents('url_for_date3'); 
    $date3obj = json_decode($date3); 
    ?> 
+0

日期的URL(使用Google日历API)也具有其他信息的负载。 –

+0

我现在把json做成了一个php对象。你是否在要求我帮助你阅读一个json文件并从中获得每一个领域? –

+0

我明白你的意思了,我应该可以从这里做到,谢谢! –