Exception when parsing an array in JSON
When I try to parse an array returned from my web-service I got this exception:
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}"
)
Here is my code:
-(void)requestFinished:(ASIHTTPRequest *)request
{
if(request.responseStatusCode==200)
{
//parse the response
NSArray *array=[[request responseString]JSONValue];
listeTypesDesCarburants=[array objectAtIndex:0];
listeDesEnseignes=[array objectAtIndex:1];
}
}
listeTypesDesCarburants
and listeDesEnseigne开发者_如何学编程s
are both a NSArray
the web-services returned me an array which is composed of two arrays:
$finalArray=array($array1,$array2);
sendResponse(200,json_encode($finalArray));
Edit:
Here is my method to parse the response :
-(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];
}
}
If I try to do this:
NSLog(@"%d",[array count]);
It gives me 0, what means that the array doesn't even received the objects, am I right?
精彩评论