【问题标题】:Rekognition Facial Recognition parsing JSON with PHP [duplicate]Rekognition面部识别用PHP解析JSON [重复]
【发布时间】:2012-11-29 00:56:35
【问题描述】:

可能重复:
Parse Json in php

我使用 API 将提交的用户图像卷曲到远程服务器,响应是 JSON,我不知道如何解析它。

这是我的 php CURL 文件

<?php
$api_key = 'xxxxxx';
$api_secret = 'xxxxx';
$Dirty_uid = $_GET['uid'];
$uid = htmlentities($Dirty_uid);
$Dirty_img = $_GET['img'];
$img = htmlentities($Dirty_img);

$query2 = 'http://rekognition.com/func/api/?api_key='.$api_key.'&api_secret='.$api_secret.'&jobs=face_recognize&urls='.$img.'&name_space=xxx&user_id=xxx';


$ch2 = curl_init();
curl_setopt($ch2, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch2, CURLOPT_URL, $query2);    // get the url contents

$data2 = curl_exec($ch2); // execute curl request
curl_close($ch2);

$json2 = json_decode($data2);
print_r($json2)
?>

这里是返回的 JSON 数据示例(通用)

代码:

{
url: "http://farm3.static.flickr.com/2566/3896283279_0209be7a67.jpg",
face_detection: [
  {
      boundingbox:
      {
        tl: {
          x: 50,
          y: 118
         },
         size:{
          width:232;
          height:232;
         }
      }
      name: "mona_lisa:0.92,barack_obama:0.02,mark_zuckerberg:0.01,"
  }
  ]

usage: {
status: "success",
quota: 999,
api_id: "xxx"
}
}

如果 json 字符串显示“名称”,我需要我的脚本仅在数字(在 : 之后高于阈值(现在假设为 .70)时打印用户名。

我该怎么做?我以前使用过 XML api,返回数据很简单 代码:

$xml = simplexml_load_string($data);

输入东西。

【问题讨论】:

    标签: php json api parsing pattern-recognition


    【解决方案1】:

    你已经拥有了大部分。你有json_decodeed 结果。现在你只需要像

    这样访问数据
    $name = $json2->face_detection[0]->name
    

    【讨论】:

    • 如何将名称(例如 mona_lisa)设置为 $var,仅当它之后的数字达到设定的阈值(例如 0.70 或更高)?
    • 所以你对 curl 或 json 解码没有问题,而是基本的字符串操作?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-03-21
    • 1970-01-01
    • 1970-01-01
    • 2017-09-01
    • 1970-01-01
    • 2017-07-31
    相关资源
    最近更新 更多