当前位置:Gxlcms > PHP教程 > phpjson接口转化为数组生成xml接口php解析jsonphpphpjsondecod

phpjson接口转化为数组生成xml接口php解析jsonphpphpjsondecod

时间:2021-07-01 10:21:17 帮助过:11人阅读

第一步:得到一个json接口,可通过一个url地址获得
第二步:通过file_get_contents取到该json串
第三步:将json格式的字符串(对象)转化为数组形式,
json_decode(json,true)json 待解码的json string字符串
当参数二为true 则结果返回的是array
第四步:foreach遍历数组成xml类型的接口

//header('content-type:application/json');$url = 'http://zphteach.com/zph/8wei/json/json.php';//拿到url地址$file = file_get_contents($url); //采集到地址的内容//echo $file;$json = json_decode($file,true);
//print_r($json) ;die;
header('content-type:application/xml'); //xml头部echo'';
echo''; //标签名对应使用foreach ($jsonas$key => $value) {
echo".$key.">";
foreach ($valueas$k => $v) {
echo"<".$k.">";
$val = str_replace("'", "'", $v); //字符串替换成xml能够解析的$val = str_replace("<", "<", $v);
echo$val;
echo".$k.">";
}
echo".$key.">";
}
echo'';

url地址得到的内容如下:

[{"name":"zhangsan's","sex":"man"},{"name":"lisi,"sex":"woman"}]

').addClass('pre-numbering').hide(); $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i <= lines; i++) { $numbering.append($('
  • ').text(i)); }; $numbering.fadeIn(1700); }); });

    以上就介绍了php json接口转化为数组 生成xml接口,包括了json,php方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

  • 人气教程排行