如何在PHP侧检索的NSMutableArray [英] How to retrieve nsmutablearray in php side

查看:114
本文介绍了如何在PHP侧检索的NSMutableArray的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用这个code时,NSMutableArray的StudentDataToSendArray发送到PHP的,我想是这样......

  AFHTT prequestOperationManager *经理= [AFHTT prequestOperationManager经理]
    [经理岗位:@HTTP://****/iStartTest.php参数:@ {@Student_TotalAverage:StudentDataToSendArray}成功:^(AFHTT prequestOperation *操作,ID responseObject)
    {
        的NSLog(@数据=%@,responseObject);
    }
          失败:^(AFHTT prequestOperation *操作,NSError *误差)
    {
        的NSLog(@错误:%@,错误);
    }];

在PHP端,使用这种code,以获取数组

  $ Student_TotalAverage = $ _ POST ['Student_TotalAverage'];$响应=阵列(计数=>计数($ Student_TotalAverage));
回声json_en code($响应);

数组大小的回声逸岸正确的。

这是没事吧?

如果是的话,我需要得到数组值。

这是code为阵

 的NSMutableArray * StudentDataToSendArray = [[NSMutableArray里的alloc]初始化];

这是NSObject的控股中的每个对象的所有值添加到NSMutableArray里

  @属性(非原子,强)的NSString * StudentNameNow;
@属性(非原子,强)的NSString * StudentIDNow;
@属性(非原子,强)的NSString * SubjectNameNow;
@属性(非原子,强)的NSString * SubjectIDNow;
@属性(非原子,强)的NSString * ClassNameNow;
@属性(非原子,强)的NSString * ClassIDNow;
@属性(非原子,强)的NSString * Exam_IDNow;
@属性(非原子,强)的NSString * MarkNow;

添加对象到nsmurablearray StudentDataToSend

  [StudentDataToSendArray ADDOBJECT:SingleStudentDetails];

我想这code,但我不断收到一个空值

  $ TEMP =电流($ Student_TotalAverage) -  GT;学生姓名;
回声json_en code($ TEMP);

  $ TEMP = $ Student_TotalAverage [0] ['StudentName'];
回声json_en code($ TEMP);
?< PHP的标题(内容类型:text / JSON); ?>
< PHP//创建连接
$ CON = mysqli_connect(***** *****。​​com,*****,******,******)或死亡( mysqli_error($ MySQL_Handle));$ sSQL ='SET CHARACTER SET UTF8';
mysqli_query($ CON,$ sSQL)或死亡(可以\\'吨字符集数据库');$测试=SET NAMES UTF8;
mysqli_query($ CON,$测试);$ Student_TotalAverage = $ _ POST ['Student_TotalAverage'];$ X codeResponse =阵列(状态=>计数($ Student_TotalAverage));
回声json_en code($ X codeResponse);//关闭康恩
mysqli_close($ CON);
?>


解决方案

非常感谢@Rob指导我正确的方向,我花了一段时间,但一切都很顺利
回答我的问题是这样的。

从tableViewCells到NSMutableArray里添加值,然后添加NSMutableArray里与主要作为ROWNUMBER到nsmutabedictionary

 的NSMutableArray * temparray = [[NSMutableArray里的alloc]初始化];
    [temparray ADDOBJECT:STID];
    [temparray ADDOBJECT:stname];
    [temparray ADDOBJECT:subjectID];
    [temparray ADDOBJECT:主旨名称];
    [temparray ADDOBJECT:的classID];
    [temparray ADDOBJECT:类名]。
    [temparray ADDOBJECT:examID];
    [temparray ADDOBJECT:标记];    [DictionaryToSend的setObject:temparray forKey:currrow];

然后路过的NSMutableDictionaryDictionaryToSend到PHP页面这个code

 的NSString * URLString = @HTTP://*********/*****/iStartTest.php
    AFHTT prequestOperationManager *经理= [AFHTT prequestOperationManager经理]
    manager.requestSerializer = [AFHTT prequestSerializer串行]。
    [经理岗位:URLString参数:@ {@DictionaryToSave:DictionaryToSend}
          成功:^(AFHTT prequestOperation *操作,ID responseObject)
    {
        的NSLog(@JSON:%@,responseObject);
    }
          失败:^(AFHTT prequestOperation *操作,NSError *误差)
    {
        的NSLog(@错误:%@,错误);
    }];

再从PHP页面读取数据,并将其插入到mysql数据库

  $ Student_Details = $ _ POST ['DictionaryToSave'];$ WW = 0;而($ WW<计数($ Student_Details))
{
$ StudentID = $ Student_Details [$ WW] [0];
$ StudentFullName = $ Student_Details [$ WW] [1];
$ SubjectID = $ Student_Details [$ WW] [2];
$主旨名称= $ Student_Details [$ WW] [3];
$ ClassNo = $ Student_Details [$ WW] [4];
$类名= $ Student_Details [$ WW] [5];
$ Exam_ID = $ Student_Details [$ WW] [6];
$马克= $ Student_Details [$ WW] [7];//做任何与此数据$ WW ++;
}

到code的任何改进是最欢迎的:)

Using this code, the nsmutablearray "StudentDataToSendArray" is sent to the php, ' i think so ' ...

 AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    [manager POST:@"http://****/iStartTest.php" parameters:@{@"Student_TotalAverage": StudentDataToSendArray} success:^(AFHTTPRequestOperation *operation, id responseObject)
    {
        NSLog(@"data = %@", responseObject);
    }
          failure:^(AFHTTPRequestOperation *operation, NSError *error)
    {
        NSLog(@"Error: %@", error);
    }];

in the php side, using this code to get the array

$Student_TotalAverage=$_POST['Student_TotalAverage'];

$Response = array("Count" => count($Student_TotalAverage));
echo json_encode($Response);

the echo of array size is infact correct.

is this all right ?

and if so, i need to get the array values.

this is the code for the array

NSMutableArray *StudentDataToSendArray = [[NSMutableArray alloc] init];

this is the NSObject Holding all values in each object added to the nsmutablearray

@property (nonatomic, strong) NSString *StudentNameNow;
@property (nonatomic, strong) NSString *StudentIDNow;
@property (nonatomic, strong) NSString *SubjectNameNow;
@property (nonatomic, strong) NSString *SubjectIDNow;
@property (nonatomic, strong) NSString *ClassNameNow;
@property (nonatomic, strong) NSString *ClassIDNow;
@property (nonatomic, strong) NSString *Exam_IDNow;
@property (nonatomic, strong) NSString *MarkNow;

adding object to the nsmurablearray StudentDataToSend

 [StudentDataToSendArray addObject:SingleStudentDetails];

i tried this code, but i keep getting a null value

$temp = current($Student_TotalAverage)-> StudentName;
echo json_encode($temp);

or

$temp = $Student_TotalAverage[0]['StudentName'];
echo json_encode($temp);


<?php header("Content-type: text/json"); ?>
<?php 

// Create connection
$con=mysqli_connect("*****.*****.com","*****","******","******") or die ( mysqli_error($MySQL_Handle) ); 

$sSQL= 'SET CHARACTER SET utf8'; 
mysqli_query($con,$sSQL) or die ('Can\'t charset in DataBase'); 

$test = "SET NAMES utf8";
mysqli_query($con,$test);

$Student_TotalAverage=$_POST['Student_TotalAverage'];

$XcodeResponse = array("status" => count($Student_TotalAverage));
echo json_encode($XcodeResponse);

// Close conn
mysqli_close($con);
?>

解决方案

many thanks to @Rob for directing me to the right direction, took me a while but all worked out well the answer to my question is this

adding the values from the tableViewCells to NSMutableArray and then adding the nsmutablearray to nsmutabedictionary with key as RowNumber

 NSMutableArray *temparray = [[NSMutableArray alloc]init ];
    [temparray addObject:stID];
    [temparray addObject:stname];
    [temparray addObject:subjectID];
    [temparray addObject:subjectname];
    [temparray addObject:classID];
    [temparray addObject:classname];
    [temparray addObject:examID];
    [temparray addObject:mark];

    [DictionaryToSend setObject:temparray forKey:currrow];

then passing the nsmutabledictionary "DictionaryToSend" to the php page with this code

NSString *URLString = @"http://*********/*****/iStartTest.php";
    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    [manager POST:URLString parameters:@{@"DictionaryToSave": DictionaryToSend}
          success:^(AFHTTPRequestOperation *operation, id responseObject)
    {
        NSLog(@"JSON: %@", responseObject);
    }
          failure:^(AFHTTPRequestOperation *operation, NSError *error)
    {
        NSLog(@"Error: %@", error);
    }];

Then Reading the data from the php page and inserting it to mysql database

$Student_Details=$_POST['DictionaryToSave'];

$ww = 0;

while ($ww < count($Student_Details))
{
$StudentID = $Student_Details[$ww][0];
$StudentFullName = $Student_Details[$ww][1];
$SubjectID = $Student_Details[$ww][2];
$SubjectName = $Student_Details[$ww][3];
$ClassNo = $Student_Details[$ww][4];
$ClassName = $Student_Details[$ww][5];
$Exam_ID = $Student_Details[$ww][6];
$Mark = $Student_Details[$ww][7];

// do whatever with the data here

$ww++;
}

any improvements to the code are most welcome :)

这篇关于如何在PHP侧检索的NSMutableArray的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆