我的 php 有一个名为 load 的方法。我可以插入不同的方法,但是当我更改参数以使用此方法时,我认为它正确发送了数据,但它没有显示在我的应用程序上。
索引.php
function load(){
//Establish connection
$con=mysqli_connect("localhost","root","","Mealidea");
// Check connection
if (mysqli_connect_errno()){
$errorR['name']="Failed to connect to mysql".mysqli_connect_error();
echo json_encode(errorR);
}
//Perform query
$result = mysqli_query($con,"SELECT * FROM User");
$myjsons = array();
while($row = mysql_fetch_assoc($result)){
$myjsons[] = $row;
}
//Close connection
mysqli_close($con);
echo json_encode($myjsons);
}
设置请求:
//Get from DB
NSURL*url=[NSURL URLWithString:@"http://localhost/Tutorials/index.php?f=load&key=6dM7V0n5GqYJLTMibQDf2gA2a94h8hbF"];
//URL request
NSURLRequest*request=[NSURLRequest requestWithURL:url];
//Set the connection
connection = [NSURLConnection connectionWithRequest:request delegate:self];
if (connection) {
webData=[[NSMutableData alloc]init];
}
得到答案:
NSDictionary*data=[NSJSONSerialization JSONObjectWithData:webData options:0 error:&error];
//If data is nil, then print error
if (data==nil) {
//NSLog(@"%@",error);
}
//Print the data
NSLog(@"%@",data);
//???? how to parse data?
NSDictionary*num=[data valueForKey:@"User"];