iosjsonnsjsonserialization

App gets crashed because object at index is beyond empty array


I am accessing data from the JSON web services into my application. whenever there is no JSON data the app gets crashed, I am using nsjsonserialization is there anyway I can find out the empty array at response itself and display the error, thus not making app gets crashed.


Solution

  • try this . . . .

    NSArray * dataArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];
    
    if (dataArray != nil) {
    
         // perform parsing
    }