程序是要输入两个json格式的txt文件,然后通过匹配两个文件的相同的index,然后输出一个新的json格式的txt文件。 比如:
这是输入的两个文件的格式:
1. product
{
product_name: string // a unique id for the product
manufacturer: string
family: string // optional grouping of products
model: string
announced-date: string // iso-8601 formatted date string, e.g. 2011-04-28t19:00:00.000-05:00
}
2. listing
{
title: string // description of product for sale
manufacturer: string // who manufactures the product for sale
currency: string // currency code, e.g. usd, cad, gbp, etc.
price: string // price, e.g. 19.99, 100.00
}
输出的文件格式为:
{
product_name: string
listings: array[listing]
}
先上代码:
baseitem.php
buildfromarray($fields);
}
/**
* @param array $fields
*/
abstract public function buildfromarray(array $fields);
/**
* @return array
*/
abstract public function converttoarray();
}
?>
listing.php
$this->title,
'manufacturer' => $this->manufacturer,
'currency' => $this->currency,
'price' => $this->price,
);
}
/**
* @inheritdoc
*/
public function buildfromarray(array $fields)
{
$this->title = $fields['title'];
$this->manufacturer = $fields['manufacturer'];
