The first step: Get a JSON interface that can be obtained from a URL address
Step two: Take the JSON string through file_get_contents
Step three: Convert a JSON-formatted string (object) into an array,
Json_decode ( Json,tRue) number of arguments : JSON string string to decode
When parameter two is true, the result is an array
Fourth step: The interface of the XML type composed of the Foreach
//header (' Content-type:application/json ');$url=' http://zphteach.com/zph/8wei/json/json.php ';//Get URL address$file= File_get_contents ($url);//Collect the contents of the address//echo $file;$json= Json_decode ($file,true);//print_r ($json);d ie;Header' Content-type:application/xml ');//xml HeadEcho'
';Echo'
'
;//tag name corresponding to useforeach($json as$key=$value) {Echo"
<>< span="">
.
$key.
">"; foreach ( $valueas$k = $v)
{ echo"<".
$k.
">";
$val = str_replace ( "'", "'", $v); ///string replaced by XML to parse
$val = Str_replace ( "<", "<", $v); Echo
$val; Echo "
. $k. ">";} Echo " <>. $key. ">";} Echo '';
The URL address gets the following:
[{"name":"zhangsan's","sex":"man"},{"name":"lisi
<>< span=""><>,"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); }); });
The above describes the PHP JSON interface conversion to generate an XML interface, including the json,php aspects of the content, I hope that the PHP tutorial interested in a friend helpful.