我正在使用y
和json_decode
来解析PHP中的json响应,但是当我尝试访问它的元素时,它不起作用,这是响应的样子
TRUE
$ responseData = json_decode($ response,TRUE); //应该将其转换为数组
我正在访问BCLS.secondaryCallResponse({"items":[{"id":4377466391001,"name":"Sample Video 2","creationDate":"1438012370879","renditions":[{"audioOnly":false,"controllerType":"DEFAULT","displayName":"Sample Asset Redpoll","encodingRate":798000,"frameHeight":360,"frameWidth":640,"id":109379493001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":2987928,"uploadTimestampMillis":1278422604020,"url":"http:\/\/brightcove.vo.llnwd.net\/e1\/uds\/pd\/96980657001\/96980657001_109379493001_Bird-CommonRedpoll-iStock-000006369683HD720.mp4","videoCodec":"H264","videoContainer":"MP4","videoDuration":29967},{"audioOnly":false,"controllerType":"DEFAULT","displayName":"Sample Asset Redpoll","encodingRate":271000,"frameHeight":180,"frameWidth":320,"id":109379483001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":1013553,"uploadTimestampMillis":1278422590621,"url":"http:\/\/brightcove.vo.llnwd.net\/e1\/uds\/pd\/96980657001\/96980657001_109379483001_Bird-CommonRedpoll-iStock-000006369683HD720.mp4","videoCodec":"H264","videoContainer":"MP4","videoDuration":29960},{"audioOnly":false,"controllerType":"DEFAULT","displayName":"Sample Asset Redpoll","encodingRate":1746000,"frameHeight":720,"frameWidth":1280,"id":109379494001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":6538469,"uploadTimestampMillis":1278422604397,"url":"http:\/\/brightcove.vo.llnwd.net\/e1\/uds\/pd\/96980657001\/96980657001_109379494001_Bird-CommonRedpoll-iStock-000006369683HD720.mp4","videoCodec":"H264","videoContainer":"MP4","videoDuration":29967},{"audioOnly":false,"controllerType":"DEFAULT","displayName":"Sample Asset Redpoll","encodingRate":413000,"frameHeight":180,"frameWidth":320,"id":109379449001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":1547446,"uploadTimestampMillis":1278422544580,"url":"http:\/\/brightcove.vo.llnwd.net\/e1\/uds\/pd\/96980657001\/96980657001_109379449001_Bird-CommonRedpoll-iStock-000006369683HD720.mp4","videoCodec":"H264","videoContainer":"MP4","videoDuration":29960},{"audioOnly":false,"controllerType":"DEFAULT","displayName":"Sample Asset Redpoll","encodingRate":1167000,"frameHeight":360,"frameWidth":640,"id":109379422001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":4370827,"uploadTimestampMillis":1278422465338,"url":"http:\/\/brightcove.vo.llnwd.net\/e1\/uds\/pd\/96980657001\/96980657001_109379422001_Bird-CommonRedpoll-iStock-000006369683HD720.mp4","videoCodec":"H264","videoContainer":"MP4","videoDuration":29967},{"audioOnly":false,"controllerType":"DEFAULT","displayName":"Sample Asset Redpoll","encodingRate":517000,"frameHeight":268,"frameWidth":480,"id":109379402001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":1937694,"uploadTimestampMillis":1278422444109,"url":"http:\/\/brightcove.vo.llnwd.net\/e1\/uds\/pd\/96980657001\/96980657001_109379402001_Bird-CommonRedpoll-iStock-000006369683HD720.mp4","videoCodec":"H264","videoContainer":"MP4","videoDuration":29967}]},{"id":4377466392001,"name":"Sample Video 1","creationDate":"1438012370884","renditions":[{"audioOnly":false,"controllerType":"DEFAULT","displayName":"Sample Asset Titmouse","encodingRate":730000,"frameHeight":360,"frameWidth":640,"id":207397055001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":752301,"uploadTimestampMillis":1279774725742,"url":"http:\/\/brightcove.vo.llnwd.net\/e1\/uds\/pd\/96980657001\/96980657001_207397055001_Bird-Titmouse-iStock-000005422648HD1080.mp4","videoCodec":"H264","videoContainer":"MP4","videoDuration":8242},{"audioOnly":false,"controllerType":"DEFAULT","displayName":"Sample Asset Titmouse","encodingRate":1791000,"frameHeight":720,"frameWidth":1280,"id":207397050001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":1844840,"uploadTimestampMillis":1279774712658,"url":"http:\/\/brightcove.vo.llnwd.net\/e1\/uds\/pd\/96980657001\/96980657001_207397050001_Bird-Titmouse-iStock-000005422648HD1080.mp4","videoCodec":"H264","videoContainer":"MP4","videoDuration":8242},{"audioOnly":false,"controllerType":"DEFAULT","displayName":"Sample Asset Titmouse","encodingRate":107000,"frameHeight":224,"frameWidth":400,"id":207397051001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":110856,"uploadTimestampMillis":1279774725067,"url":"http:\/\/brightcove.vo.llnwd.net\/e1\/uds\/pd\/96980657001\/96980657001_207397051001_Bird-Titmouse-iStock-000005422648HD1080.mp4","videoCodec":"H264","videoContainer":"MP4","videoDuration":8267},{"audioOnly":false,"controllerType":"DEFAULT","displayName":"Sample Asset Titmouse","encodingRate":446000,"frameHeight":268,"frameWidth":480,"id":207397052001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":459435,"uploadTimestampMillis":1279774725177,"url":"http:\/\/brightcove.vo.llnwd.net\/e1\/uds\/pd\/96980657001\/96980657001_207397052001_Bird-Titmouse-iStock-000005422648HD1080.mp4","videoCodec":"H264","videoContainer":"MP4","videoDuration":8242},{"audioOnly":false,"controllerType":"DEFAULT","displayName":"Sample Asset Titmouse","encodingRate":1117000,"frameHeight":404,"frameWidth":720,"id":207397049001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":1151256,"uploadTimestampMillis":1279774712501,"url":"http:\/\/brightcove.vo.llnwd.net\/e1\/uds\/pd\/96980657001\/96980657001_207397049001_Bird-Titmouse-iStock-000005422648HD1080.mp4","videoCodec":"H264","videoContainer":"MP4","videoDuration":8242},{"audioOnly":false,"controllerType":"DEFAULT","displayName":"Sample Asset Titmouse","encodingRate":252000,"frameHeight":224,"frameWidth":400,"id":207397056001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":259671,"uploadTimestampMillis":1279774725855,"url":"http:\/\/brightcove.vo.llnwd.net\/e1\/uds\/pd\/96980657001\/96980657001_207397056001_Bird-Titmouse-iStock-000005422648HD1080.mp4","videoCodec":"H264","videoContainer":"MP4","videoDuration":8242}]}],"page_number":0,"page_size":2,"total_count":-1});
,它只显示$responseData[0]
,我做错了什么?
答案 0 :(得分:1)
你可以试试这个:
$data='{"items":[{"id":4377466391001,"name":"Sample Video 2","creationDate":"1438012370879","renditions":[{"audioOnly":false,"controllerType":"DEFAULT","displayName":"Sample Asset Redpoll","encodingRate":798000,"frameHeight":360,"frameWidth":640,"id":109379493001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":2987928,"uploadTimestampMillis":1278422604020,"url":"http:\/\/brightcove.vo.llnwd.net\/e1\/uds\/pd\/96980657001\/96980657001_109379493001_Bird-CommonRedpoll-iStock-000006369683HD720.mp4","videoCodec":"H264","videoContainer":"MP4","videoDuration":29967},{"audioOnly":false,"controllerType":"DEFAULT","displayName":"Sample Asset Redpoll","encodingRate":271000,"frameHeight":180,"frameWidth":320,"id":109379483001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":1013553,"uploadTimestampMillis":1278422590621,"url":"http:\/\/brightcove.vo.llnwd.net\/e1\/uds\/pd\/96980657001\/96980657001_109379483001_Bird-CommonRedpoll-iStock-000006369683HD720.mp4","videoCodec":"H264","videoContainer":"MP4","videoDuration":29960},{"audioOnly":false,"controllerType":"DEFAULT","displayName":"Sample Asset Redpoll","encodingRate":1746000,"frameHeight":720,"frameWidth":1280,"id":109379494001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":6538469,"uploadTimestampMillis":1278422604397,"url":"http:\/\/brightcove.vo.llnwd.net\/e1\/uds\/pd\/96980657001\/96980657001_109379494001_Bird-CommonRedpoll-iStock-000006369683HD720.mp4","videoCodec":"H264","videoContainer":"MP4","videoDuration":29967},{"audioOnly":false,"controllerType":"DEFAULT","displayName":"Sample Asset Redpoll","encodingRate":413000,"frameHeight":180,"frameWidth":320,"id":109379449001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":1547446,"uploadTimestampMillis":1278422544580,"url":"http:\/\/brightcove.vo.llnwd.net\/e1\/uds\/pd\/96980657001\/96980657001_109379449001_Bird-CommonRedpoll-iStock-000006369683HD720.mp4","videoCodec":"H264","videoContainer":"MP4","videoDuration":29960},{"audioOnly":false,"controllerType":"DEFAULT","displayName":"Sample Asset Redpoll","encodingRate":1167000,"frameHeight":360,"frameWidth":640,"id":109379422001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":4370827,"uploadTimestampMillis":1278422465338,"url":"http:\/\/brightcove.vo.llnwd.net\/e1\/uds\/pd\/96980657001\/96980657001_109379422001_Bird-CommonRedpoll-iStock-000006369683HD720.mp4","videoCodec":"H264","videoContainer":"MP4","videoDuration":29967},{"audioOnly":false,"controllerType":"DEFAULT","displayName":"Sample Asset Redpoll","encodingRate":517000,"frameHeight":268,"frameWidth":480,"id":109379402001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":1937694,"uploadTimestampMillis":1278422444109,"url":"http:\/\/brightcove.vo.llnwd.net\/e1\/uds\/pd\/96980657001\/96980657001_109379402001_Bird-CommonRedpoll-iStock-000006369683HD720.mp4","videoCodec":"H264","videoContainer":"MP4","videoDuration":29967}]},{"id":4377466392001,"name":"Sample Video 1","creationDate":"1438012370884","renditions":[{"audioOnly":false,"controllerType":"DEFAULT","displayName":"Sample Asset Titmouse","encodingRate":730000,"frameHeight":360,"frameWidth":640,"id":207397055001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":752301,"uploadTimestampMillis":1279774725742,"url":"http:\/\/brightcove.vo.llnwd.net\/e1\/uds\/pd\/96980657001\/96980657001_207397055001_Bird-Titmouse-iStock-000005422648HD1080.mp4","videoCodec":"H264","videoContainer":"MP4","videoDuration":8242},{"audioOnly":false,"controllerType":"DEFAULT","displayName":"Sample Asset Titmouse","encodingRate":1791000,"frameHeight":720,"frameWidth":1280,"id":207397050001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":1844840,"uploadTimestampMillis":1279774712658,"url":"http:\/\/brightcove.vo.llnwd.net\/e1\/uds\/pd\/96980657001\/96980657001_207397050001_Bird-Titmouse-iStock-000005422648HD1080.mp4","videoCodec":"H264","videoContainer":"MP4","videoDuration":8242},{"audioOnly":false,"controllerType":"DEFAULT","displayName":"Sample Asset Titmouse","encodingRate":107000,"frameHeight":224,"frameWidth":400,"id":207397051001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":110856,"uploadTimestampMillis":1279774725067,"url":"http:\/\/brightcove.vo.llnwd.net\/e1\/uds\/pd\/96980657001\/96980657001_207397051001_Bird-Titmouse-iStock-000005422648HD1080.mp4","videoCodec":"H264","videoContainer":"MP4","videoDuration":8267},{"audioOnly":false,"controllerType":"DEFAULT","displayName":"Sample Asset Titmouse","encodingRate":446000,"frameHeight":268,"frameWidth":480,"id":207397052001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":459435,"uploadTimestampMillis":1279774725177,"url":"http:\/\/brightcove.vo.llnwd.net\/e1\/uds\/pd\/96980657001\/96980657001_207397052001_Bird-Titmouse-iStock-000005422648HD1080.mp4","videoCodec":"H264","videoContainer":"MP4","videoDuration":8242},{"audioOnly":false,"controllerType":"DEFAULT","displayName":"Sample Asset Titmouse","encodingRate":1117000,"frameHeight":404,"frameWidth":720,"id":207397049001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":1151256,"uploadTimestampMillis":1279774712501,"url":"http:\/\/brightcove.vo.llnwd.net\/e1\/uds\/pd\/96980657001\/96980657001_207397049001_Bird-Titmouse-iStock-000005422648HD1080.mp4","videoCodec":"H264","videoContainer":"MP4","videoDuration":8242},{"audioOnly":false,"controllerType":"DEFAULT","displayName":"Sample Asset Titmouse","encodingRate":252000,"frameHeight":224,"frameWidth":400,"id":207397056001,"referenceId":null,"remoteStreamName":null,"remoteUrl":null,"size":259671,"uploadTimestampMillis":1279774725855,"url":"http:\/\/brightcove.vo.llnwd.net\/e1\/uds\/pd\/96980657001\/96980657001_207397056001_Bird-Titmouse-iStock-000005422648HD1080.mp4","videoCodec":"H264","videoContainer":"MP4","videoDuration":8242}]}],"page_number":0,"page_size":2,"total_count":-1}';
$sample=json_decode($data);
var_dump($sample->items);
答案 1 :(得分:1)
您有两种选择:
1)转换为关联数组 - foreach ($json['items'] as $item) {
//for example, show first rendition for each item
print_r($item['renditions'][0]);
}
:
$json = json_decode('{"items":[ ...')
2)转换为stdClasses - foreach ($json->items as $item) {
//for example, show first rendition for each item
print_r($item->renditions[0]);
}
:
<asp:HyperLink ID="HyperLink112" runat="server"
NavigateUrl='~/Admin/NewsContentPage.aspx?NewsId=<%# Eval("NewsId") %>' Text='<%# Eval("NewsTitle") %>' />