sadik hasan sadik hasan - 27 days ago 6
iOS Question

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.

Answer Source

try this . . . .

NSArray * dataArray = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:nil];

if (dataArray != nil) {

     // perform parsing
}