使用php读取json代码参数


Read json code parameter with php

我想用php读取这个json id。json代码:

<program id="2395">foo program</program> 
php代码:

$jsonList = json_decode($jsonCode,true);
foreach ($jsonList as $child) {
   echo $child["program"]->id;
}

如何调用id?它不是这样的

这是xml而不是json,您可以尝试simplexml来解析xml字符串:

$xmlString = '<program id="2395">foo program</program>';
$sxe = new SimpleXMLElement($xmlString);
echo $sxe['id']; // 2395

这个例子是用simplexmlelement(表示XML文档中的一个元素)完成的。