[ios+php Jason format for sending and parsing]

Source: Internet
Author: User

Server-side PHP file connect.php:

<?PHP$q=mysql_connect("localhost", "root", "" "); if(!$q)    {        die(' Could not connect: '.Mysql_error()); }    mysql_query("Set names UTF8");//reading data with UTF8    mysql_select_db("Jasontest",$q);//Database    $sql= "SELECT * from UserInfo"; $query=mysql_query($sql);  while($row=Mysql_fetch_array($query)){                    $com=$row; }    EchoJson_encode ($com);?>

iOS segment parsing:

-(Ibaction) Clickbutton: (IDSender {[Nsthread detachnewthreadselector: @selector (getjasonstring) totarget:self Withobject:nil];}-(void) getjasonstring{Nserror*error; //loading a Nsurl objectNsurlrequest *request2 = [Nsurlrequest requestwithurl:[nsurl urlwithstring:@"http://localhost/jasontest/connect.php"]]; //put the requested URL data into the NSData objectNSData *response =[nsurlconnection sendsynchronousrequest:request2 returningresponse:nil Error:nil]; //IOS5 self-contained parsing class Nsjsonserialization parse data from response into a dictionaryNsdictionary *jasondic = [nsjsonserialization jsonobjectwithdata:response options:nsjsonreadingmutableleaves Error: &ERROR]; NSLog (@"Person ' s userid is%@", [Jasondic Objectforkey:@"userid"]); NSLog (@"Person ' s name is%@", [Jasondic Objectforkey:@"name"]); NSLog (@"Person ' s password is%@", [Jasondic Objectforkey:@"Password"]); NSLog (@"Person ' s Phoneno is%@", [Jasondic Objectforkey:@"Phoneno"]); }

[ios+php Jason format for sending and parsing]

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.