获取特定字段(Json/PHP)

获取特定字段(Json/PHP),php,json,Php,Json,我试图从下面的json响应中获取一个特定的字段。我使用的是Amazon SNS,我希望得到输出键变量(“key”:“4177/media/test1.mp4”),并且只返回4177。因此,基本上我想要得到第一个/on输出键变量之前的内容。我该怎么办?提前谢谢你的时间 { "state" : "COMPLETED", "version" : "2012-09-25", "jobId" : "1443105433825-ax3k5c", "pipelineId

我试图从下面的json响应中获取一个特定的字段。我使用的是Amazon SNS,我希望得到输出键变量(“key”:“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\u decode(file\u get\u contents)获取jsonphp://input",对),

试试这个

 $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
试试这个

 $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

$msgs['outputs'][0]['key']
$msgs['outputs']
是一个对象数组。如果您只需要一个以上的对象,则可以在其上循环。但是,这不起作用,谢谢您的帮助。
$msgs['outputs'][0]['key']
$msgs['outputs']
是一个对象数组。如果您只需要一个以上的对象,您可以循环使用它。但是,这不起作用,谢谢您的帮助。我使用$a=json\u decode(file\u get\u contents('php://input",对),;$c=json_解码($a)$d=$c->输出[0]->键$e=爆炸(“/”,d美元);echo$e[0];//输出为4177,电流不工作,有输入吗?响应为空。您从文件获取的内容是什么?我使用的是amazon SNS服务,它基本上在上面发布json输出。judst do print_r(文件获取内容('php://input",对),;看看你得到了什么,现在我让它工作了,不过,它是test.mp4而不是4177。谢谢你的帮助。谢谢。我正在使用$a=json解码(文件获取内容('php://input",对),;$c=json_解码($a)$d=$c->输出[0]->键$e=爆炸(“/”,d美元);echo$e[0];//输出为4177,电流不工作,有输入吗?响应为空。您从文件获取的内容是什么?我使用的是amazon SNS服务,它基本上在上面发布json输出。judst do print_r(文件获取内容('php://input",对),;看看你得到了什么,现在我让它工作了,不过,它是test.mp4而不是4177。谢谢你的帮助。谢谢