【发布时间】:2015-03-13 04:53:03
【问题描述】:
在下面的xml文件“目录”中,每个书的id有5个变量。
<?xml version="1.0"?>
<catalog>
<book id="bk101">
<author>Gambardella</author>
<title>XML Developer</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
</book>
<book id="bk102">
<author>Ralls</author>
<title>Midnight Rain</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-12-16</publish_date>
</book>
<book id="bk103">
<author>Corets</author>
<title>Maeve Ascendant</title>
<genre>Fantasy</genre>
<price>5.95</price>
<publish_date>2000-11-17</publish_date>
</book>
</catalog>
如何在 php.ini 中获取特定 Book id(即 book id ="102")的 json 数组。 我搜索了网络,但无法以所需的方式找到解决方案。 任何人都可以帮助我吗? xml 文件:www.mywebsite.com/catlog.xml
$data = json_decode($json, true);
foreach ( $data['catlog'] as $row ) {
if ($row['book id'] =='102') {
// do the work here
}
}
【问题讨论】:
-
@Paul Crovella:在 php 中解析 json 数组
-
在问题中添加了json php代码