将JSON响应转换为PHP变量
我有一个使用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*', ' — ', '*description*', ' in ', '*location*'] 
    }); 
我想要做的是在每个事件PHP变量的数据的存储区不同的部分,例如:
<?php     $date= JSON Date 
    <--! For next event !--> 
    $date2= JSON Date2 
    $date3= JSON Date3 
    ?> 
我只需要3,因为它只会显示3即将发生的事件。
回答:
<?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); 
    ?> 
以上是 将JSON响应转换为PHP变量 的全部内容, 来源链接: utcz.com/qa/266743.html








