我正在尝试从以下json响应中获取特定字段。我正在使用Amazon SNS,我想获得输出键变量("键":" 4177 / media / test1.mp4")并且只返回4177.所以基本上我想要获取第一个/ on输出键变量之前的任何内容。我该怎么做?先谢谢你的时间。
{
"state" : "COMPLETED",
"version" : "2012-09-25",
"jobId" : "1443105433825-ax3k5c",
"pipelineId" : "1442869133716-ncyq63",
"input" : {
"key" : "sample.mp4",
"frameRate" : "auto",
"resolution" : "auto",
"aspectRatio" : "auto",
"interlaced" : "auto",
"container" : "auto"
},
"outputs" : [ {
"id" : "1",
"presetId" : "1443042941302-mvvgq6",
"key" : "4177/media/test1.mp4",
"thumbnailPattern" : "4177/thumbs/test1-{count}",
"rotate" : "auto",
"status" : "Complete",
"statusDetail" : "The input file for this job contains 6 audio channels and the preset is configured for 2 audio channels. Amazon Elastic Transcoder audio-channel mapping may not result in the desired audio.",
"duration" : 6,
"width" : 1280,
"height" : 720
} ]
}
我通过$ msgs = json_decode抓取json(file_get_contents(' php://输入'),true);
答案 0 :(得分:0)
试试这个
$a =' {
"state" : "COMPLETED",
"version" : "2012-09-25",
"jobId" : "1443105433825-ax3k5c",
"pipelineId" : "1442869133716-ncyq63",
"input" : {
"key" : "sample.mp4",
"frameRate" : "auto",
"resolution" : "auto",
"aspectRatio" : "auto",
"interlaced" : "auto",
"container" : "auto"
},
"outputs" : [ {
"id" : "1",
"presetId" : "1443042941302-mvvgq6",
"key" : "4177/media/test1.mp4",
"thumbnailPattern" : "4177/thumbs/test1-{count}",
"rotate" : "auto",
"status" : "Complete",
"statusDetail" : "The input file for this job contains 6 audio channels and the preset is configured for 2 audio channels. Amazon Elastic Transcoder audio-channel mapping may not result in the desired audio.",
"duration" : 6,
"width" : 1280,
"height" : 720
} ]
}';
$c = json_decode($a);
$d = $c->outputs[0]->key;
$e = explode("/",$d);
echo $e[0];// output is 4177