我通过API收集xml格式的一些数据,并希望在对象列表中反序列化它.
我正在使用Symfony2并找出JMSSerializerBundle,但我真的不知道如何使用它.
我知道Sf2允许将对象序列化/反序列化到数组,但我正在寻找更具体的东西.
例如,对于这个类:
class Screenshot
{
/**
* @var integer $id
*/
private $id;
/**
* @var string $url_screenshot
*/
private $url_screenshot;
public function __construct($id, $url_screenshot) {
$this->id = $id;
$this->url_screenshot = $url_screenshot;
}
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set url_screenshot
*
* @param string $urlScreenshot
*/
public function setUrlScreenshot($urlScreenshot)
{
$this->url_screenshot = $urlScreenshot;
}
/**
* Get url_screenshot
*
* @return string
*/
public function getUrlScreenshot()
{
return $this->url_screenshot;
}
/**
* Serializes the Screenshot object.
*
* @return string
*/
public function serialize()
{
return serialize(array(
$this->id,
$this->url_screenshot
));
}
/**
* Unserializes the Screenshot object.
*
* @param string $serialized
*/
public function unserialize($serialized)
{
list(
$this->id,
$this->url_screenshot
) = unserialize($serialized);
}
public function __toString() {
return "id: ".$this->id
."screenshot: ".$this->url_screenshot;
}
}
我想序列化/反序列化到这种xml:
1
screenshot_url1
2
screenshot_url2
3
screenshot_url3
我真的想要使用集成/集成在Sf2中的东西(“光滑”的东西)并且更喜欢避免使用任何自制的xml解析器.