在JSON中解析数组时出现异常

时间:2011-05-03 22:30:32

标签: web-services json ios nsarray

当我尝试解析从我的web服务返回的数组时,我得到了这个例外:

2011-05-03 23:28:10.021  -JSONValue failed. Error trace is: (
    "Error Domain=org.brautaset.JSON.ErrorDomain Code=11 \"Unexpected end of string\" UserInfo=0x803d8b0 {NSLocalizedDescription=Unexpected end of string}"
)

这是我的代码:

-(void)requestFinished:(ASIHTTPRequest *)request
{   
    if(request.responseStatusCode==200)
    {
        //parse the response
        NSArray *array=[[request responseString]JSONValue];
        listeTypesDesCarburants=[array objectAtIndex:0];
        listeDesEnseignes=[array objectAtIndex:1];
    }
}

listeTypesDesCarburantslisteDesEnseignes都是NSArray web-services返回了一个由两个数组组成的数组:

$finalArray=array($array1,$array2);
sendResponse(200,json_encode($finalArray));

修改

以下是解析响应的方法:

-(void)requestFinished:(ASIHTTPRequest *)request
{
    if(request.responseStatusCode==200)
    {
        //parse the response
        NSArray *array=[[request responseString]JSONValue];
        listeTypesDesCarburants=[array objectAtIndex:0];
        listeDesEnseignes=[array objectAtIndex:1];  
    }
    else
    {
        UIAlertView *alert=[[UIAlertView alloc]initWithTitle:@"TopStation"
                                                     message:@"Unexpected error"
                                                    delegate:nil
                                           cancelButtonTitle:@"OK"
                                           otherButtonTitles:nil];
        [alert show];
        [alert release];    
    }
}

如果我尝试这样做:

NSLog(@"%d",[array count]);

它给了我0,这意味着数组甚至没有收到对象,我是对的吗?

0 个答案:

没有答案