获取特定字段(Json/PHP)


Get Specific Field (Json/PHP)

我试图从下面的json响应中获得一个特定的文件。我正在使用亚马逊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
  } ]
}

我正在抓取json $msgs = json_decode(file_get_contents('php://input'), true);

try this

 $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