JSON 和 restful API 使用

1.JSON模块的使用

use JSON;

#将perl数据转为JSON

my $json = to_json($data);

#将JSON字符串转为perl数据结构

my $decoded = from_json($json_string);

2.数据库交互

use DBI;

my $dbh = DBI->connect("");

my $sth = $dbh->prepare("SELECT sql sentence");

$sth->execute($gene_id);

my $row = $sth->fetchrow_hashref/

print $cgi->header('application/json');

print to_json($row);