此行
my $json = new JSON(autoconv => 0); # <-- line X
引發此錯誤爲什麼我會得到「用法:JSON :: XS :: new(klass)」錯誤?
Usage: JSON::XS::new(klass) at (...) line X
有什麼不對?
這是一個跟進我的問題Is there a way to force quotation of numbers in JSON 1.x Perl module?
此行
my $json = new JSON(autoconv => 0); # <-- line X
引發此錯誤爲什麼我會得到「用法:JSON :: XS :: new(klass)」錯誤?
Usage: JSON::XS::new(klass) at (...) line X
有什麼不對?
這是一個跟進我的問題Is there a way to force quotation of numbers in JSON 1.x Perl module?
JSON模塊changed substantially在1.15和2.00之間的API。爲JSON 1.x編寫的代碼不一定適用於JSON 2.x.特別是,1.x構造函數帶有可選參數。 2.x構造函數不帶任何參數;相反,你在構建之後使用了mutator函數。
如果你必須支持某種原因,既JSON 1.x和2.x,你需要檢查是否JSON->VERSION < 2
(實際上JSON->VERSION < 1.99
如果算上2.X API的開發版本),並有兩個版本你的代碼,一個用於1.x API和一個用於2.x.
供參考:http://search.cpan.org/~makamaka/JSON-2.53/lib/JSON.pm可以閱讀* 2.x中的新方法不再使用任何參數。你可以改爲設置參數; *用下面的例子'$ json = JSON-> new-> pretty;' –
不再使用die.net,它已經過時。請參閱[metacpan.org](https://metacpan.org)獲取模塊文檔,[perldoc.perl.org](http://perldoc.perl.org)獲取核心Perl文檔和[kernel.org](http: //www.kernel.org/doc/man-pages/)/[he.net](http://man.he.net)爲genereal手冊頁。 – daxim