i am geting data in a nsmutabledictionay from api and i need to add this data into tableview cell, so i need to convert it into nsmutable array. but when tried to add data from dictonary to aarray it picks only last object of dictonary. pleae look at my code and response.
i need to parse stop1 and stop2 address
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:theRequest
completionHandler:
^(NSData *data, NSURLResponse *response, NSError *error) {
NSLog(@"Response:%@ %@\n", response, error);
if(error == nil)
{
NSString * text = [[NSString alloc] initWithData: data encoding: NSUTF8StringEncoding];
NSLog(@"Data = %@",text);
}
dictionary = [[NSJSONSerialization JSONObjectWithData:data options:0 error:nil]objectForKey:@"data"];
NSMutableDictionary *temp = [NSMutableDictionary new];
NSArray *IDArray = [dictionary objectForKey:@"docs"];
for (NSDictionary *Dict in IDArray)
{
[temp setObject:[Dict objectForKey:@"_id"] forKey:@"_id"];
NSLog(@"id %@", temp);
}
[getid addObject:temp];
NSLog(@"getid details %@", getid);
if (getid)
{
[_ScheduleRidetable reloadData];
}
}];
this is my response which i get in console
id {
"_id" = 573c1beb7051509c0ec94936;
}
2016-05-18 14:41:48.641 GGR Driver Staging[11546:6724511] id {
"_id" = 573c17f8261b2bc76e228721;
}
2016-05-18 14:41:48.642 GGR Driver Staging[11546:6724511] id {
"_id" = 573c0f20261b2bc76e22871e;
}
2016-05-18 14:41:48.642 GGR Driver Staging[11546:6724511] id {
"_id" = 573c0eb4261b2bc76e22871d;
}
2016-05-18 14:41:48.643 GGR Driver Staging[11546:6724511] id {
"_id" = 573c0e15261b2bc76e22871c;
}
2016-05-18 14:41:48.644 GGR Driver Staging[11546:6724511] id {
"_id" = 573c0d0c261b2bc76e22871b;
}
2016-05-18 14:41:48.645 GGR Driver Staging[11546:6724511] id {
"_id" = 573c0c5f261b2bc76e22871a;
}
2016-05-18 14:41:48.646 GGR Driver Staging[11546:6724511] id {
"_id" = 573c0acf261b2bc76e228717;
}
2016-05-18 14:41:48.647 GGR Driver Staging[11546:6724511] getid details (
{
"_id" = 573c0acf261b2bc76e228717;
}
)
{"message":"success","data":{"docs":[{"_id":"573c1beb7051509c0ec94936","user":{"phone":"9574863210","image":"","name":"user12"},"distance":45123,"bookingNumber":"429r2ckh8pa8","bookingType":0,"paymentMode":"Card","tip":0,"estimatedFare":103.99,"estimatedDuration":"4557","created":"2016-05-18T07:38:12.037Z","stop2":{"address":"New Delhi, New Delhi 110001, India","location":[28.6139391,77.2090212]},"stop1":{"address":"Sector 18, Noida, Uttar Pradesh 201301, India","location":[28.570317000000003,77.3218196]},"destination":{"address":"Gurgaon, Haryana 122001, India","location":[28.459496499999997,77.0266383]},"currentLocation":{"address":"A20A Block, Sector 58","location":[28.6024597,77.3609439]}},{"_id":"573c17f8261b2bc76e228721","user":{"phone":"9988776655","image":"","name":"Chandan"},"distance":5003,"bookingType":0,"paymentMode":"Card","tip":0,"estimatedFare":14.83,"estimatedDuration":"703","created":"2016-05-17T07:44:02.130Z","stop2":{"location":[]},"stop1":{"location":[]},"destination":{"address":"Noida City Center, Noida, Uttar Pradesh, India","location":[28.5748053,77.35633740000003]},"currentLocation":{"address":"A20, A Block, Sector 58, Noida, Uttar Pradesh 201301, India","location":[28.6024597,77.36094389999994]}},{"_id":"573c0f20261b2bc76e22871e","user":{"phone":"9988776655","image":"","name":"Chandan"},"distance":5003,"bookingType":0,"paymentMode":"Card","tip":0,"estimatedFare":14.83,"estimatedDuration":"703","created":"2016-05-17T07:44:02.130Z","stop2":{"location":[]},"stop1":{"location":[]},"destination":{"address":"Noida City Center, Noida, Uttar Pradesh, India","location":[28.5748053,77.35633740000003]},"currentLocation":{"address":"A20, A Block, Sector 58, Noida, Uttar Pradesh 201301, India","location":[28.6024597,77.36094389999994]}},{"_id":"573c0eb4261b2bc76e22871d","user":{"phone":"9988776655","image":"","name":"Chandan"},"distance":9913,"bookingType":0,"paymentMode":"Card","tip":0,"estimatedFare":31.71,"estimatedDuration":"1533","created":"2016-05-17T07:44:02.130Z","stop2":{"location":[]},"stop1":{"location":[]},"destination":{"address":"Noida, Uttar Pradesh, India","location":[28.5355161,77.39102649999995]},"currentLocation":{"address":"A20, A Block, Sector 58, Noida, Uttar Pradesh 201301, India","location":[28.6024597,77.36094389999994]}},{"_id":"573c0e15261b2bc76e22871c","user":{"phone":"9988776655","image":"","name":"Chandan"},"distance":5003,"bookingType":0,"paymentMode":"Card","tip":0,"estimatedFare":14.83,"estimatedDuration":"703","created":"2016-05-17T07:44:02.130Z","stop2":{"location":[]},"stop1":{"location":[]},"destination":{"address":"Noida City Center, Noida, Uttar Pradesh, India","location":[28.5748053,77.35633740000003]},"currentLocation":{"address":"A20, A Block, Sector 58, Noida, Uttar Pradesh 201301, India","location":[28.6024597,77.36094389999994]}},{"_id":"573c0d0c261b2bc76e22871b","user":{"phone":"9988776655","image":"","name":"Chandan"},"distance":5003,"bookingType":0,"paymentMode":"Card","tip":0,"estimatedFare":14.83,"estimatedDuration":"703","created":"2016-05-17T07:44:02.130Z","stop2":{"location":[]},"stop1":{"location":[]},"destination":{"address":"Noida City Center, Noida, Uttar Pradesh, India","location":[28.5748053,77.35633740000003]},"currentLocation":{"address":"A20, A Block, Sector 58, Noida, Uttar Pradesh 201301, India","location":[28.6024597,77.36094389999994]}},{"_id":"573c0c5f261b2bc76e22871a","user":{"phone":"9988776655","image":"","name":"Chandan"},"distance":5003,"bookingType":0,"paymentMode":"Card","tip":0,"estimatedFare":14.83,"estimatedDuration":"703","created":"2016-05-17T07:44:02.130Z","stop2":{"location":[]},"stop1":{"location":[]},"destination":{"address":"Noida City Center, Noida, Uttar Pradesh, India","location":[28.5748053,77.35633740000003]},"currentLocation":{"address":"A20, A Block, Sector 58, Noida, Uttar Pradesh 201301, India","location":[28.6024597,77.36094389999994]}},{"_id":"573c0acf261b2bc76e228717","user":{"phone":"9988776655","image":"","name":"Chandan"},"distance":5003,"bookingType":0,"paymentMode":"Card","tip":0,"estimatedFare":14.83,"estimatedDuration":"703","created":"2016-05-17T07:44:02.130Z","stop2":{"location":[]},"stop1":{"location":[]},"destination":{"address":"Noida City Center, Noida, Uttar Pradesh, India","location":[28.5748053,77.35633740000003]},"currentLocation":{"address":"A20, A Block, Sector 58, Noida, Uttar Pradesh 201301, India","location":[28.6024597,77.36094389999994]}}],"total":10,"limit":8,"page":":1","pages":2}}
This is my api form there i get response.
NSURL *theURL = [NSURL URLWithString:@"http://qa.networc.in:1336/api/dispatcher/rideScheduled/:1"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:theURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:20.0f];
//Specify method of request(Get or Post)
[theRequest setHTTPMethod:@"GET"];
//Pass some default parameter(like content-type etc.)
[theRequest setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[theRequest setValue:@"application/json; charset=UTF-8" forHTTPHeaderField:@"Content-Type"];
[theRequest addValue:token forHTTPHeaderField:@"x-access-token"];
NSURLResponse *theResponse = NULL;
NSError *theError = NULL;
NSData *responseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&theResponse error:&theError];
if (responseData == nil)
{
return;
}
NSDictionary *dataDictionaryResponse = [NSJSONSerialization JSONObjectWithData:responseData options:0 error:&theError];
NSLog(@"url to send request= %@",theURL);
NSLog(@"%@",dataDictionaryResponse);