JSON :: XS“用法"发牢骚

编程入门 行业动态 更新时间:2024-10-27 22:22:36
本文介绍了JSON :: XS“用法"发牢骚的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我似乎无法正确使用JSON::XS的OO接口.以下错误伴我无法追踪:

I can't seem to use JSON::XS's OO interface properly. The following croaks with an error I can't track down:

use JSON::XS; my $array = ['foo', 'bar']; my $coder = JSON::XS->new->utf8->pretty; print $coder->encode_json($array);

此错误与以下内容有关:Usage: JSON::XS::encode_json(scalar) at test.pl line 5.我一直在梳理JSON::XS的代码,但在任何地方都找不到用法:"警告.我的用法似乎与文档中的示例非常匹配.谁能告诉我我哪里出问题了?

This croaks with the following: Usage: JSON::XS::encode_json(scalar) at test.pl line 5. I have been combing through the code for JSON::XS and I can't find a "Usage:" warning anywhere. My usage seems to be pretty well matched with the examples in the documentation. Can anyone tell me where I have gone wrong?

推荐答案

JSON::XS 具有两个接口:功能和面向对象.

JSON::XS has two interfaces: functional and OO.

  • 在功能界面中,功能名称为encode_json.
  • 在OO界面中,方法只是encode,而不是encode_json.
  • In the functional interface, the function name is encode_json.
  • In the OO interface, the method is simply encode, not encode_json.

以下两个摘录均起作用:

Both of the following two snippets work:

# Functional | # OO ------------------------------+----------------------------------------- | use JSON::XS; | use JSON::XS; my $array = ['foo', 'bar']; | my $array = [ 'foo', 'bar' ]; | print encode_json($array); | my $coder = JSON::XS->new->utf8->pretty; | print $coder->encode($array); | # ["foo","bar"] | # [ | # "foo", | # "bar" | # ]

更多推荐

JSON :: XS“用法"发牢骚

本文发布于:2023-11-09 09:08:45,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1571988.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:JSON   XS   quot

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!