首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何从PHP [开放alpr的JSON结果]读取这种类型的Json文件?

如何从PHP [开放alpr的JSON结果]读取这种类型的Json文件?
EN

Stack Overflow用户
提问于 2020-07-16 01:59:15
回答 1查看 188关注 0票数 0

我需要知道如何提取JSON数据,比如下面发布到php的JSON格式,我试图使用php脚本将Json文件键值数据提取到mysql中。下面的JSON来自openalpr,在命令行上使用alpr作为json导出

代码语言:javascript
复制
  "version": 2,
  "data_type": "alpr_results",
  "epoch_time": 1594858871000,
  "img_width": 3232,
  "img_height": 3232,
  "processing_time_ms": 522.5,
  "regions_of_interest": [],
  "results": [
    {
      "plate": "QAA1989C",
      "confidence": 90.09095,
      "matches_template": 0,
      "plate_index": 0,
      "region": "my",
      "region_confidence": 0,
      "processing_time_ms": 42.125999,
      "requested_topn": 10,
      "coordinates": [
        {
          "x": 1149,
          "y": 2071
        },
        {
          "x": 1836,
          "y": 2071
        },
        {
          "x": 1836,
          "y": 2268
        },
        {
          "x": 1149,
          "y": 2268
        }
      ]
    }
  ]
}

我一直得到的只是类似于这个Illegal string offset 'result 的错误,这是我测试过的显示板块号的php代码:能帮助我如何使用脚本获取json数组中的子数组的值吗?谢谢**

我使用了以下代码,不确定有关子元素的键值的错误是什么

代码语言:javascript
复制
$filename = "results.json";
          $data = file_get_contents($filename); //Read the JSON file in PHP
          $array = json_decode($data, true); //Convert JSON String into PHP Array
          
          foreach ($data['results']['results'] AS $d)
          {
            echo $d['plate'];
            }
EN

回答 1

Stack Overflow用户

发布于 2020-07-16 02:12:16

您的json字符串错了,第一行缺少{

代码语言:javascript
复制
$json = '
{
    "version": 2,
    "data_type": "alpr_results",
    "epoch_time": 1594858871000,
    "img_width": 3232,
    "img_height": 3232,
    "processing_time_ms": 522.5,
    "regions_of_interest": [],
    "results": [
        {
            "plate": "QAA1989C",
            "confidence": 90.09095,
            "matches_template": 0,
            "plate_index": 0,
            "region": "my",
            "region_confidence": 0,
            "processing_time_ms": 42.125999,
            "requested_topn": 10,
            "coordinates": [
                {
                    "x": 1149,
                    "y": 2071
                },
                {
                    "x": 1836,
                    "y": 2071
                },
                {
                    "x": 1836,
                    "y": 2268
                },
                {
                    "x": 1149,
                    "y": 2268
                }
            ]
        }
    ]
}
';

$data = json_decode($json,true);

foreach ($data['results'] AS $d) {
    echo $d['plate'];
}
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/62926271

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档