English 中文(简体)
是否有办法通过PHP自动将XML网页改为JSON? [复制]
原标题:Is there a way to convert an XML page to JSON automatically via PHP? [duplicate]
This question already has answers here:
Closed 11 years ago.

Possible Duplicate:
PHP convert XML to JSON

这里,我对我的产出XML的样本认为:

<item>
 <Barcode>0602527522593</Barcode>
 <albumid>1818</albumid>
 <Title>Gold</Title>
 <Country>Sweden</Country>
 <Format>CD</Format>
 <Length></Length>
 <Number_of_Discs></Number_of_Discs>
 <Type>album</Type>
 <Description></Description>
 <Band_or_Artist>Adams, Ryan</Band_or_Artist>
</item>

是否容易使用现成的植物检疫功能或添加剂,以迅速将这种功能转化成个人,并产生这种功能? 如果它不是建构的,那么我应该使用哪一个延伸?

最佳回答

您可使用简单的XML(http://php.net/manual/en/book.simplexml.php)阅读XML的投入,然后使用json_encode(http://php.net/manual/en/book.json.php)制作产出。

也许,你只是想把 no子放在一阵列上,把一切都用标签作为钥匙,这应当非常简单。

问题回答

作为在客户方面采取这种做法的一种替代做法是:http://www.fnerwork.com/jquery/xml-to-json/ conf=“noestlow” (X) 和Jons pluby >。

有很多东西。 http://www.ibm.com/developerwork/xml/library/x-xml2jsonphp/“rel=“nofollow”http://www.ibm.com/developerwork/xml/library/x-xml2jsonphp/

与此类似?

<?php

$xmlstr = "<item>
 <Barcode>0602527522593</Barcode>
 <albumid>1818</albumid>
 <Title>Gold</Title>
 <Country>Sweden</Country>
 <Format>CD</Format>
 <Length></Length>
 <Number_of_Discs></Number_of_Discs>
 <Type>album</Type>
 <Description></Description>
 <Band_or_Artist>Adams, Ryan</Band_or_Artist>
</item>";

$movies = new SimpleXMLElement($xmlstr);
echo $output = json_encode($movies);
?>




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签