我已經JSON解析在Xcode中,像這樣:試圖在Xcode NSCocoaErrorDomain代碼來解析JSON = 3840
-(void)getCheckUserData:(NSData *)data {
NSError *error;
if (!error) {
checkUserJSON = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
}
else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:@"Uh Oh" message:@"Spaghetti-O" delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
[alert show];
}
}
-(void) startCheckingUserLogin {
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:kCheck_user]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:20.0];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest
delegate:self];
if (theConnection) {
NSURL *url = [NSURL URLWithString:kCheck_user];
NSData *data = [NSData dataWithContentsOfURL:url];
[self getCheckUserData:data];
}
}
但是我僱了一名Web開發人員,他更新了從phpMyAdmin的數據了我的過時的PHP文件和用JSON編碼它。現在我在xcode中得到NSCocoaErrorDomain Code = 3840消息。
這裏是php文件我抓住從數據:
<?php
require_once('classes/secure.php');
$SECURE = new Secure();
if(!isset($_POST[ 'var1' ])) { exit("ERROR: no var1"); }
if(!isset($_POST[ 'var2' ])) { exit("ERROR: no var2"); }
$VARONE = $_POST[ 'var1' ];
$VARTWO = $_POST[ 'var2' ];
$RESULT = $SECURE->checkPassword($VARONE, $VARTWO); // Check VARONE/VARTWO
unset($SECURE); // Unset Secure
exit(json_encode($RESULT)); // Return result as JSON string
?>
我需要做什麼改變嗎?
您可以手動執行對Web服務的請求(即不通過應用程序)並編輯您的文章以包含結果嗎?換句話說,你確定你的json是合法的嗎? –