PHP JSON interface conversion array generation XML interface PHP parsing json php php json decod

Source: Internet
Author: User
Tags php json tag name
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.

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.