0
私はいくつかのWebサービスを持っています。JSONコードを取得して配列に入れたいと思います。 JSONを配列に入れよう
この
は私のコードです:NSArray * mnewarray;
@try {
mnewarray = [self JsonToArray:[NSString stringWithFormat:@"%@/WS_Get_APEM_Staff.php",_GV.WSpath]];
}
@catch (NSException *e) {
}
ここで
- (NSArray *) JsonToArray:(NSString *)mURLString{
NSURL *url = [NSURL URLWithString:[mURLString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]];
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:url];
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSError *jsonParsingError = nil;
NSArray *result = [NSJSONSerialization JSONObjectWithData:response options:NSJSONReadingMutableContainers error:&jsonParsingError];
NSLog(@"Result= %@",result);
return result;
}
は私のWebサービス
<?php
$error = ["error" => "1"];
include "_Connect.php";
$tsql = "SELECT *
FROM staff";
$stmt = sqlsrv_query($conn, $tsql);
if($stmt)
{
$a=0;
echo "[";
while($object = sqlsrv_fetch_object($stmt)) { if($a==1) echo ","; echo json_encode($object); $a=1; }
echo "]";
}else
echo json_encode($error);
include "_Disconnect.php";
?>
であり、これは何であるか、そのポストJSON
[{"employeeusername":"123","employeepassword":"123","employeename":"nnnnnnnnnnnn","employeeactive":1,"trabajador":null,"id_staff":1}
{"employeeusername":"456","employeepassword":"456","employeename":"oooooooooo","employeeactive":1,"trabajador":null,"id_staff":2},
{"employeeusername":"789","employeepassword":"789","employeename":"yyyyyyyyyyy","employeeactive":1,"trabajador":null,"id_staff":3},
{"employeeusername":"ewer","employeepassword":"ewer","employeename":"xxxxxxx","employeeactive":1,"trabajador":null,"id_staff":4},
{"employeeusername":"asdfg","employeepassword":"asdfg","employeename":"asdfghj","employeeactive":1,"trabajador":null,"id_staff":5}]
問題は結果が空になり、コードが実行されず、例外が発生することです。これで私を助けてください。
作品を?してみてくださいこの質問はすでに投稿されています。https://stackoverflow.com/questions/12582166/how-to-display-an-json-array-in-xcode?rq=1 –
ok投稿を編集してください。 1分 –
私は要求を投稿 –