サーバーからphpページにアクセスしようとしていますが、戻りません。サイト アドレス (site1111111) を別のアドレス (site222222) に変更すると、コードが機能するため、以下のコードは問題ありません。site2 は JSON.aspx を使用していますが、コードはわかりませんが、次のように返されます。
{aaaa:false}
編集して追加: 問題があるかどうかはわかりません。site1111111 と言うと、実際には site222222/subfolder/ です。編集を終了します。
私の PHP コードは単純なテストです。同じ json 文字列を入力するだけです。
<html><body>
$arr = array ('aaaa'=>false);
echo json_encode($arr);
</body></html>
iOS アプリのコードは次のとおりです。
NSString *urlString = @"http://site111111111111111111/welcome.php";
//urlString = @"http://site222222222222/JSON.aspx?function=ffff&item=aaaa";
NSURL *url = [NSURL URLWithString:urlString];
NSError *error;
NSData *data = [NSData dataWithContentsOfURL:url options:NSDataReadingUncached error:&error];
NSLog(@"%@", data);
//<7b226973 64696769 74616c22 3a66616c 73657d> //print data from site2222222
//<3c68746d 6c3e0d0a 3c626f64 793e0d0a 0d0a3c21 2d2d5765 6c636f6d 65203c62 723e0d0a 596f7572 20656d61 696c2061 64647265 73732069 733a200d 0a2d2d3e 0d0a0d0a 7b226973 64696769 74616c22 3a66616c 73657d0d 0a3c2f62 6f64793e 0d0a3c2f 68746d6c 3e0d0a> //data from site11111
if (error)
{
NSLog(@"error==%@==",[error localizedDescription]);
}
else
{
NSLog(@"no error for request"); //both site1111 and site2222 print this out
NSError *errorInJsonParsing;
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&errorInJsonParsing];
if(errorInJsonParsing)
{
NSLog(@"error in json==%@==",[error localizedDescription]);
}
else
{
if ([[json valueForKey:@"aaaa"] boolValue] ) {
NSLog(@"YES");
} else {
NSLog(@"NO");
}
}
}
コードを実行すると、if 条件 if(errorInJsonParsing) から出力された null json を取得しました。
私のphpとiosリクエストを接続するものを見逃すかどうかはわかりません。助けてください。ティア!