json - 如何将 DBIx::Class::ResultSet 转换为 JSON
问题描述
我正在尝试从 DBIx::Class::ResultSet 获取 JSON,但出现异常
encountered object 'Sql2Json::Model::DB::Book=HASH(0x6014f88)',
but neither allow_blessed, convert_blessed nor allow_tags settings are
enabled (or TO_JSON/FREEZE method missing)
控制器类是Books.pm:
package Sql2Json::Controller::Books;
use Moose;
use namespace::autoclean;
use JSON::XS;
BEGIN { extends 'Catalyst::Controller'; }
my $json = JSON::XS->new;
sub list : Local {
my($self, $c) = @_;
$c->stash(books_rs => $c->model('DB::Book'));
$c->stash(books => [$c->stash->{books_rs}->search({}, {order_by => 'name ASC'})]);
$c->stash(json_data => $json->convert_blessed->encode($c->stash->{books}));
$c->forward('View::JSON');
}
__PACKAGE__->meta->make_immutable;
1;
根据这篇文章,祝福对象的编码就足够了:
$json->convert_blessed->encode($c->stash->{books})
我在这里错过了什么吗?
解决方案
推荐阅读
- python - 将csv导入mysql数据库
- python - Python:将字符串(%,括号,',')中的多种格式转换为数字
- php - 改进 json 格式数据中的 JWT 异常处理
- python - 前句的命名实体识别影响
- microsoft-graph-api - 使用 Microsoft Graph REST API 时出现模棱两可的 ErrorQuotaExceeded 消息
- python - GPSD 在启动时无法正常启动
- windows - 用于文件复制的 Windows 批处理命令
- osgi - OSGi 配置管理和元类型服务
- javascript - 使用javascript限制用户响应的数量
- java - 我如何访问从 jframe 到 jpanel 的方法?