Php 正在尝试在Xcode NSCOCAERRORDOMain Code=3840中解析JSON

Php 正在尝试在Xcode NSCOCAERRORDOMain Code=3840中解析JSON,php,ios,json,Php,Ios,Json,我一直在Xcode中解析JSON,如下所示: -(void)getCheckUserData:(NSData *)data { NSError *error; if (!error) { checkUserJSON = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error]; } else{ UIAlertView *alert = [[UIAlertView alloc]i

我一直在Xcode中解析JSON,如下所示:

-(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开发人员,他更新了我过时的php文件,这些文件从phpmyadmin获取数据并用JSON编码。现在我在xcode中得到一条NSCOCAerorDomain代码=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服务在99%的时间内运行良好,但对一个端点的一个响应(带有某些参数)失败。我在RESTClient中运行了这个请求,并在标题中注意到响应是ISO-8859-1,又称拉丁语-1

诀窍是将Latin-1数据转换为NSString,然后使用NSString将其转换回UTF8数据,以使NSJSONSerialization愉快

NSError *error;
NSArray *json = [NSJSONSerialization JSONObjectWithData:self->receivedData options:0 error:&error];
if (!json && error && [error.domain isEqualToString:NSCocoaErrorDomain] && (error.code == NSPropertyListReadCorruptError)) {
    // Encoding issue, try Latin-1
   NSString *jsonString = [[NSString alloc] initWithData:self->receivedData encoding:NSISOLatin1StringEncoding];
   if (jsonString) {
        // Need to re-encode as UTF8 to parse, thanks Apple
        json = [NSJSONSerialization JSONObjectWithData:
                [jsonString dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]
            options:0 error:&error];
    }
}

我肯定有很多很棒的REST工具,你可能想看看其中的一些。RESTClient是Firefox的插件。

问题在于编码。我有一个web服务在99%的时间内运行良好,但对一个端点的一个响应(带有某些参数)失败。我在RESTClient中运行了这个请求,并在标题中注意到响应是ISO-8859-1,又称拉丁语-1

诀窍是将Latin-1数据转换为NSString,然后使用NSString将其转换回UTF8数据,以使NSJSONSerialization愉快

NSError *error;
NSArray *json = [NSJSONSerialization JSONObjectWithData:self->receivedData options:0 error:&error];
if (!json && error && [error.domain isEqualToString:NSCocoaErrorDomain] && (error.code == NSPropertyListReadCorruptError)) {
    // Encoding issue, try Latin-1
   NSString *jsonString = [[NSString alloc] initWithData:self->receivedData encoding:NSISOLatin1StringEncoding];
   if (jsonString) {
        // Need to re-encode as UTF8 to parse, thanks Apple
        json = [NSJSONSerialization JSONObjectWithData:
                [jsonString dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]
            options:0 error:&error];
    }
}

我肯定有很多很棒的REST工具,你可能想看看其中的一些。RESTClient是Firefox的插件。

问题在于编码。我有一个web服务在99%的时间内运行良好,但对一个端点的一个响应(带有某些参数)失败。我在RESTClient中运行了这个请求,并在标题中注意到响应是ISO-8859-1,又称拉丁语-1

诀窍是将Latin-1数据转换为NSString,然后使用NSString将其转换回UTF8数据,以使NSJSONSerialization愉快

NSError *error;
NSArray *json = [NSJSONSerialization JSONObjectWithData:self->receivedData options:0 error:&error];
if (!json && error && [error.domain isEqualToString:NSCocoaErrorDomain] && (error.code == NSPropertyListReadCorruptError)) {
    // Encoding issue, try Latin-1
   NSString *jsonString = [[NSString alloc] initWithData:self->receivedData encoding:NSISOLatin1StringEncoding];
   if (jsonString) {
        // Need to re-encode as UTF8 to parse, thanks Apple
        json = [NSJSONSerialization JSONObjectWithData:
                [jsonString dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]
            options:0 error:&error];
    }
}

我肯定有很多很棒的REST工具,你可能想看看其中的一些。RESTClient是Firefox的插件。

问题在于编码。我有一个web服务在99%的时间内运行良好,但对一个端点的一个响应(带有某些参数)失败。我在RESTClient中运行了这个请求,并在标题中注意到响应是ISO-8859-1,又称拉丁语-1

诀窍是将Latin-1数据转换为NSString,然后使用NSString将其转换回UTF8数据,以使NSJSONSerialization愉快

NSError *error;
NSArray *json = [NSJSONSerialization JSONObjectWithData:self->receivedData options:0 error:&error];
if (!json && error && [error.domain isEqualToString:NSCocoaErrorDomain] && (error.code == NSPropertyListReadCorruptError)) {
    // Encoding issue, try Latin-1
   NSString *jsonString = [[NSString alloc] initWithData:self->receivedData encoding:NSISOLatin1StringEncoding];
   if (jsonString) {
        // Need to re-encode as UTF8 to parse, thanks Apple
        json = [NSJSONSerialization JSONObjectWithData:
                [jsonString dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES]
            options:0 error:&error];
    }
}

我肯定有很多很棒的REST工具,你可能想看看其中的一些。RESTClient是Firefox的插件。

您是否可以手动(即不通过应用程序)执行对web服务的请求,并编辑您的帖子以包含结果?换句话说,你确定你的json是合法的吗?你能手动执行对web服务的请求(即不是通过应用程序)并编辑你的帖子以包含结果吗?换句话说,你确定你的json是合法的吗?你能手动执行对web服务的请求(即不是通过应用程序)并编辑你的帖子以包含结果吗?换句话说,你确定你的json是合法的吗?你能手动执行对web服务的请求(即不是通过应用程序)并编辑你的帖子以包含结果吗?换句话说,你确定你的json是合法的吗?只是说:如果服务器发送ISO-8859-1中应该是json的内容,那么它就不是有效的json,服务器就坏了。JSON是UTF-8、UTF-16或UTF-32。没别的。只是说:如果服务器发送ISO-8859-1中应该是JSON的内容,那么它就不是有效的JSON,服务器就坏了。JSON是UTF-8、UTF-16或UTF-32。没别的。只是说:如果服务器发送ISO-8859-1中应该是JSON的内容,那么它就不是有效的JSON,服务器就坏了。JSON是UTF-8、UTF-16或UTF-32。没别的。只是说:如果服务器发送ISO-8859-1中应该是JSON的内容,那么它就不是有效的JSON,服务器就坏了。JSON是UTF-8、UTF-16或UTF-32。没有别的了。