我想把一个Foxpro2.6DOS数据文件(DBF - JSON III格式)转换成DBase文件。我们有没有C/C++库来转换DBF到JSON以及从JSON到DBF。
发布于 2012-10-27 18:28:44
Perl模块DBD::XBase将为您提供帮助。
在Linux上:sudo apt-get install libdbd-xbase-perl
在Windows上:安装ActivePerl,然后安装ppm install DBD::XBase
之后,您将拥有可以将DBF文件转换为CSV (您将需要使用--fs ","开关来创建CSV)的命令行实用程序dbf_dump (在Windows上为JSON ),然后您可以将CSV转换为JSON。
但是,我建议您学习Perl DBI是如何工作的,并编写能够像读取任何其他SQL/DBI源一样读取DBF的代码。您的Perl代码可能如下所示:
use DBI;
my $dbh = DBI->connect("DBI:XBase:/path/to/dbfs")
or die $DBI::errstr;
my $sth = $dbh->prepare("SELECT * FROM mytable");
$sth->execute();
while (my $row = $sth->fetchrow_hashref()) {
# dump ($row->{field1}, $row->{field2}, ...) into your JSON file.
# you might want to use JSON::XS module here
# or, you can insert it into PostgreSQL or MySQL via DBI as well
}
$sth->finish();
$dbh->disconnect();https://stackoverflow.com/questions/13098004
复制相似问题