Advertise here




Advertise here

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

exception when parsing an array in JSON

lucaazorilucaazori Posts: 48Registered Users
edited May 2011 in iOS SDK Development
hi all, 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
listeDesEnseignes
are both a `NSArray`
Post edited by lucaazori on
· ·

Replies

  • JasonRJasonR San Diego, CAPosts: 1,587Registered Users @ @ @ @
    edited May 2011
    That error means the JSON you are parsing is badly formatted. You'll have to fix the server you are downloading from.
    My development blog: <a href="http://jrinn.com" target="_blank">http://jrinn.com</a>;
    · ·
  • dany_devdany_dev Posts: 4,696Tutorial Authors, Registered Users @ @ @ @ @
    edited May 2011
    NSLog(@"%@",[request responseString]);
    

    post the response....
    · ·
  • lucaazorilucaazori Posts: 48Registered Users
    edited May 2011
    hi ,actually i have already make another JSON request that communicate with the same server, so the server is fine, however i googled somewhere and i found that may be the problem is that, for this JSON request, i'm not passing any parameter, i only receive response, also it may be that, in the URL i specify the file where the web-service is like that :
    http://myServer.com/admin_V01/stationsProcessing/pickers_management.php
    
    because the other web-service for the JSON request above was in index.php so the url was :
    http://myServer.com.com/admin_V01/stationsProcessing/
    
    should it be in an index file ? am i obliged to send parameters with the request? otherwise help please 'cause my issue still unresolved, thx in advance :)
    · ·
  • dany_devdany_dev Posts: 4,696Tutorial Authors, Registered Users @ @ @ @ @
    edited May 2011
    i'm starting to think that you don't understand the problem and what are you trying to do. :rolleyes:


    again......post the response
    NSLog(@"%@",[request responseString]);
    
    · ·
  • lucaazorilucaazori Posts: 48Registered Users
    edited May 2011
    if(request.responseStatusCode==200) { //on d[code]if(request.responseStatusCode==200)
    {
    //on d
    · ·
  • dany_devdany_dev Posts: 4,696Tutorial Authors, Registered Users @ @ @ @ @
    edited May 2011
    i don't see NSLog of string Response

    NSLog(@"My String Response is: %@",[request responseString]);

    However is clear that is not a JSON string.....and basically this is the problem.
    · ·
  • lucaazorilucaazori Posts: 48Registered Users
    edited May 2011
    2011-05-04 12:35:57.253 TopStation[502:207] My String Response is: 
    2011-05-04 12:35:57.254 TopStation[502:207] -JSONValue failed. Error trace is: (
        "Error Domain=org.brautaset.JSON.ErrorDomain Code=11 \"Unexpected end of string\" UserInfo=0x6b23330 {NSLocalizedDescription=Unexpected end of string}"
    )
    
    · ·
  • dany_devdany_dev Posts: 4,696Tutorial Authors, Registered Users @ @ @ @ @
    edited May 2011
    ok, so it is a empty. and you can understand that you can't parse a empty string as JSON, right?
    · ·
  • lucaazorilucaazori Posts: 48Registered Users
    edited May 2011
    Hi, please forgive me and million thx for your help, i forgot to do the json_encode in my web-service before sending, million thx dany :)
    · ·
  • dany_devdany_dev Posts: 4,696Tutorial Authors, Registered Users @ @ @ @ @
    edited May 2011
    nice!. :)
    · ·
Sign In or Register to comment.