我得到的是应该读我的类别,并把它们放在一个CSV文件,这个Perl代码。经过多次尝试后,我终于获得了它,但只准备了超过500个类别中的50个。任何方式来修改这个例程来阅读我所有的类别。我需要一个JSON文件转换成可读的CSV
这里是Perl文件我从论坛的Bigcommerce了。
use strict;
use JSON::PP;
open (my $fh, "<", 'categories.json');
my $json_text = <$fh>;
my $perl_scalar = decode_json($json_text);
# Make a list of ids to names, so that I can build a content path for Neto category CSV
my $id;
foreach my $element (@$perl_scalar)
{
$id->{$element->{id}}=$element->{name};
}
# Actually print out the CSV content, in Neto's required format.
print "content type,content path,name,description 1,description 2,sort order,seo meta description,seo page title,seo meta keywords\n";
foreach my $element (@$perl_scalar)
{
print "Product Category,";
my $parent_category = $element->{parent_category_list}[0];
if ($parent_category == $element->{id})
{
print ",";
}
else
{
print $id->{$parent_category}, ",";
}
print $element->{name}, ",", $element->{description}, ",,", $element->{sort_order}, ",", $element->{meta_description}, ",,\n";
}
在此先感谢
我敢肯定这是Perl代码,而不是PHP。 –
欢迎来到Stack Overflow。通常如果你在这里问一个问题,你应该展示你的尝试,并解释问题是什么。你可以看到[faq]并参加[tour](http://stackoverflow.com/tour)。我不认为你熟悉编程,所以这可能不会帮助你。 – simbabque
**这里有一个技巧,但:**程序读取一个叫做'categories.json'文件,我相信你知道如何运行该程序。它所做的只是从该JSON文件中读取和重新排列数据。找出该文件的创建位置,并从您自己的系统中重新生成该文件。在Bigcommerce社区中询问。因为该文件只有这50个类别。如果它有你的所有类别,它会做你想做的。 – simbabque