【问题标题】:Get Specific Field (Json/PHP)获取特定字段 (Json/PHP)
【发布时间】:2015-09-24 14:53:04
【问题描述】:

我正在尝试从以下 json 响应中获取特定文件。我正在使用 Amazon SNS,我想获取输出键变量(“key”:“4177/media/test1.mp4”)并且只返回 4177。所以基本上我想获得第一个 / 输出之前的任何内容关键变量。我该怎么办?提前感谢您的时间。

    {
    "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(file_get_contents('php://input'), true); 抓取 json;

【问题讨论】:

  • $msgs['outputs'][0]['key']$msgs['outputs'] 是一个对象数组。如果您期望不止一个对象,则可以循环遍历它。
  • 这不起作用,但是,感谢您的帮助。

标签: php json


【解决方案1】:

试试这个

 $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 = json_decode(file_get_contents('php://input'), true); $c = json_decode($a); $d = $c->输出[0]->键; $e = explode("/",$d); echo $e[0];// 输出为 4177,当前不工作,有输入吗?回复为空白。
  • 你从 file_get_contents() 得到什么??
  • 我正在使用亚马逊 SNS 服务,它基本上发布了上面的 json 输出。
  • 判断 print_r(file_get_contents('php://input'), true);看看你得到了什么
  • 好的,现在我可以正常工作了,但是,它正在拉取 test.mp4 而不是 4177。任何帮助表示赞赏。谢谢。
猜你喜欢
  • 2016-04-29
  • 1970-01-01
  • 2019-04-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多