Php unlimited data JSON format and JS parsing _ PHP Tutorial

Source: Internet
Author: User
Php unlimited data JSON format and JS parsing. Flash needs data in JSON format, so it has the following code: (PHP implementation, C #, similar, go to the JSON library by yourself ~~) Copy the code as follows: -- query the user's deprecation information and return data in JSON format required by J Flash. Therefore, the following code is available: (PHP implementation, C # is similar, go to the JSON library and go to the next page ~~)

The code is as follows:


// -- Query User deprecation information and return JSON for flash
If (! Empty ($ _ GET ['action']) &! Empty ($ _ GET ['input']) {
// Fixed parameter requests will return information
If ($ _ GET ['action'] = 'getinfo' & $ _ GET ['input'] = 1 ){
// Data entity, an entity class
Class UcInvite {
// --- Display the data used
Public $ fuid; // user ID
Public $ funame; // User name
Public $ furl; // User space address
// --- Display the data used
Public $ fchilds; // A collection of child classes
}
$ Invitecount = 0; // total quantity, used to record the total offline quantity
// Recursive implementation method
Function GetShowTreeInvite ($ uid ){
Global $ _ SGLOBAL, $ invitecount;
// Organize and query SQL statements. fuid indicates the deprecation id, uid indicates the parent id, and fusername indicates the username.
$ Inv_ SQL = "select fuid, fusername from". tname ("invite"). "where uid =". $ uid;
$ Inv_query = $ _ SGLOBAL ['DB']-> query ($ inv_ SQL );
// The following table and returned array
$ Index = 0;
$ InviteTree = Array ();
$ Invitezcount = 0; // number of sub-classes
// Add information to the array cyclically
While ($ v = $ _ SGLOBAL ['DB']-> fetch_array ($ inv_query )){
$ Ui = new UcInvite ();
$ Ui-> fuid = $ v ['fuid'];
$ Ui-> funame = $ v ['fusername'];
$ Ui-> furl = "/home/space. php? Uid = ". $ v ['fuid'];
// Call yourself to recursively query subclass information
$ Ui-> fchilds = GetShowTreeInvite ($ v ['fuid']);
// Insert the returned array
$ InviteTree [$ index] = $ ui;
$ Index ++;
$ Invitecount ++;
$ Invitezcount ++;
}
// Record the current number of Deprecations
$ InviteTree ['invitezcount'] = $ invitezcount;
// Returns Array Information
Return $ inviteTree;
}
$ Fuid = empty ($ _ GET ['fuid'])? $ Space [uid]: $ _ GET ['fuid'];
// Query information based on the current user ID and return a set
$ InviteTree = GetShowTreeInvite ($ fuid );
// Record the total number of Deprecations
$ InviteTree ['invitecount'] = $ invitecount;
// Introduce the json Library. here Services_JSON is used.
// The Built-in JSON function is not used because the server is PHP5.2 or later.
Require_once ('../plugins/JSON. php ');
// Json output
$ Json = new Services_JSON ();
Echo $ json-> encode ($ inviteTree );
Exit;
} Else {
Echo 'request Parameter error! ';
Exit;
}
}
// -- Query User deprecation information and return JSON for flash


The preceding code returns a JSON string, for example:
{'0': {'fuid': '000000', 'funame': 'Guo ziwon ', 'furl':'/home/space. php? Uid = 950 ', 'fchilds': {'invitezcount': 0 }}, 'invitezcount': 1, 'invitecount': 1}
Only one
Next, use JS to parse the following:

The code is as follows:


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.