错误使用我的 $json_data = decode_json(<$fh>);

问题描述 投票:0回答:0

我是一个 perl 菜鸟,试图运行一个简单的 perl JSON 示例赢得 JSON perl 模块 并且找不到行的问题:

我的 $json_data = decode_json(<$fh>);

我收到以下错误。任何帮助将不胜感激。

Susan@Kona MINGW64 /c/data/data/data/quickPerlTest $ perl 测试.pl , 或 } 预期在解析对象/哈希时,在 test.pl 第 9 行的字符偏移量 3(在“(字符串结尾)”之前)。

use JSON;

# open the json file
my $json_file = 'example_json.json';

open(my $fh, '<', $json_file) or die "Could not open file '$json_file' $!";

# decode the json file  
my $json_data = decode_json(<$fh>);

# access the elements of the json file
foreach my $item ( @{$json_data->{items}} ) {
    print "ID: $item->{id}\n";
    print "Title: $item->{title}\n";
}


Susan@Kona MINGW64 /c/data/data/data/quickPerlTest
$ cat example_json.json
{
  "glossary": {
    "title": "example glossary",
    "GlossDiv": {
      "title": "S",
      "GlossList": {
        "GlossEntry": {
          "ID": "SGML",
          "SortAs": "SGML",
          "GlossTerm": "Standard Generalized Markup Language",
          "Acronym": "SGML",
          "Abbrev": "ISO 8879:1986",
          "GlossDef": {
            "para": "A meta-markup language.",
            "GlossSeeAlso": [ "GML", "XML" ]
          },
          "GlossSee": "markup"
        }
      }
    }
  }
}

Susan@Kona MINGW64 /c/data/data/data/quickPerlTest $ perl --version | grep 版本 这是为 x86_64-msys-thread-multi 构建的 perl 5,版本 36,subversion 0 (v5.36.0)

json perl
© www.soinside.com 2019 - 2024. All rights reserved.