Actually I am using now JSON classes for calling web-services but now i want to call that webservice using NSURLConnection any one provide me code for that.
Please provide me details of frameworks what i have to import.
Thank you in advance.
NSURL *url = [NSURL URLWithString:stringurl];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
NSOperationQueue *queue = [[NSOperationQueue alloc] init];
[NSURLConnection sendAsynchronousRequest:urlRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *error)
{
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:data options:kNilOptions error:&error];
NSLog(#"%#",dictionary);
}];
You Can use this.
You can Do like this using Synchronous :
NSURL *url=[NSURL URLWithString:urlString];
NSURLRequest *req=[NSURLRequest requestWithURL:url];
NSData *data=[NSURLConnection sendSynchronousRequest:req returningResponse:nil error:nil];
NSString *response=[[NSString alloc]initWithData:data encoding:NSUTF8StringEncoding];
NSDictionary *dd=[response JSONValue];
OR Using Delegate Method
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:urlString]];
NSURLResponse *response = nil;
// Create url connection and fire request
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
#pragma mark NSURLConnection Delegate Methods
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
// A response has been received, this is where we initialize the instance var you created
// so that we can append data to it in the didReceiveData method
// Furthermore, this method is called each time there is a redirect so reinitializing it
// also serves to clear it
_responseData = [[NSMutableData alloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
// Append the new data to the instance variable you declared
NSString* newStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data
options:kNilOptions
error:&error];
// NSArray* latestLoans = [json objectForKey:#"loans"];
NSLog(#"json: %#", json);
[_responseData appendData:data];
}
- (NSCachedURLResponse *)connection:(NSURLConnection *)connection
willCacheResponse:(NSCachedURLResponse*)cachedResponse {
// Return nil to indicate not necessary to store a cached response for this connection
return nil;
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
// The request is complete and data has been received
// You can parse the stuff in your instance variable now
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
// The request has failed for some reason!
// Check the error var
}
Use below code forrcalling SOAP web service (POST) :
-(NSString *)posturl:(NSString *)url withpoststring:(NSString *)postString {
NSString *post = postString;
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:#"%lu", (unsigned long)[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSString *URL = url;
NSLog(#"%#", URL);
NSLog(#"%#",post);
[request setURL:[NSURL URLWithString:URL]];
[request setHTTPMethod:#"POST"];
[request setValue:postLength forHTTPHeaderField:#"Content-Length"];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Content-Type"];
[request setHTTPBody:postData];
NSError *error;
NSURLResponse *response;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *data = [[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
if ([data isEqualToString:#""]) {
} else {
data = stringByStrippingHTML(data);
}
return data;
}
Related
I have this code;
NSString *post = [NSString stringWithFormat:#"latitude=%lf&longitude=%lf&provider=network&accuracy=%lf&hiz=%lf&retrieveTime=%#",
locationManager.location.coordinate.latitude,
locationManager.location.coordinate.longitude,
locationManager.location.horizontalAccuracy,
locationManager.location.speed,
dateString];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:#"%lu", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSString *sUrl = [[NSUserDefaults standardUserDefaults] stringForKey:#"serviceUrl"];
NSString *swoclString = [NSString stringWithFormat:#"%#/saveLocation.php", sUrl];
[request setURL:[NSURL URLWithString:swoclString]];
[request setHTTPMethod:#"POST"];
[request setValue:postLength forHTTPHeaderField:#"Content-Type"];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
if(conn) {
NSLog(#"Location Save Successfully");
} else {
NSLog(#"Location Save Error");
}
I can receive the data in the server side. And on the iOS side I can see the log "Location Save Successfully".
How can I receive the response from the server without implementing other methods?
Use NSURLSession instead of NSURLConnection to post your data to the Server. Below is an example how you can post JSON.
NSURLSessionConfiguration *config = [NSURLSessionConfiguration defaultSessionConfiguration];
NSURLSession *session = [NSURLSession sessionWithConfiguration:config delegate:nil delegateQueue:nil];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:#"<YOUR-URL-STRING>"] cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:120.0];
[request setHTTPMethod:#"POST"];
[request addValue:#"application/json" forHTTPHeaderField:#"Content-Type"];
[request addValue:#"application/json" forHTTPHeaderField:#"Accept"];
NSError *error;
NSData *postData = [NSJSONSerialization dataWithJSONObject:<YOUR_JSON_DATA> options:NSJSONWritingPrettyPrinted error:&error];
NSString *tmp = [[NSString alloc]initWithData:postData encoding:NSUTF8StringEncoding];
[request setHTTPBody:postData];
NSURLSessionDataTask *dataTask = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
NSHTTPURLResponse *resp = (NSHTTPURLResponse *) response;
NSLog(#"%li",(long)resp.statusCode);
if(resp.statusCode==200){
NSMutableArray *result = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&jsonError];
}];`
The block is used to return the response by the server. For example the HTTP-Status Code and the response data. If you use json you can convert the Data with the NSJSONSerialization class.
If you are using latest ios coding standards you must have to use URLSession object to send any request to the API calls because DEPRECATED: The NSURLConnection class should no longer be used. NSURLSession is the replacement for NSURLConnection. But still, if you want to continue with an old procedure, there are three ways to send API request.
P1:
-(void)procedure1{
NSURLRequest *requestObject = nil; /** replace with your request object **/
NSURLResponse *serverResponse = nil;
NSError *connectError = nil;
/* thread bloker request */
NSData *responseData = [NSURLConnection sendSynchronousRequest:requestObject returningResponse:&serverResponse error:&connectError];
if (connectError == nil) {
//parse server response data (i.e, json or xml)
}else{
/* handle connection error */
}
}
P2:
-(void)procedure2{
NSURLRequest *requestObject = nil; /** replace with your request object **/
/* thread free request */
[NSURLConnection sendAsynchronousRequest:requestObject queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse * _Nullable response, NSData * _Nullable data, NSError * _Nullable connectionError) {
if (connectionError == nil) {
//parse server response data (i.e, json or xml)
}else{
/* handle connection error */
}
}];
}
P3:
the last one is a bit different than the other two,
#interface TestViewController ()<NSURLConnectionDelegate>
#property (nonatomic, retain) NSMutableData* responseData;
#end
-(void)procedure3{
NSURLRequest *requestObject = nil; /** replace with your request object **/
NSURLConnection *connectionObject = [NSURLConnection connectionWithRequest:requestObject delegate:self];
[connectionObject start];
}
here in this procedure you are required to invoke NSURLConnectionDelegate methods
- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[self.responseData setLength:0];
}
- (void) connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
[self.responseData appendData:data];
}
- (void) connectionDidFinishLoading:(NSURLConnection *)connection {
NSString* responseString = [[NSString alloc] initWithData:self.responseData encoding:NSUTF8StringEncoding];
connection = nil;
}
I have made a login form. Fields r email and password. Now i want to POST the data from fields to specific url how it can be done. I'm totally new to IOS. Can anybody help me?? How to do HTTP request and JSON parsing?
/*********See this**********/
-(void)webServiceCall{
NSString *dataToSend = [NSString stringWithFormat:#"Username=%#&Password=%#“,<userIdEnter Here>,<Password enter here>];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
NSString *Length = [NSString stringWithFormat:#"%d",[postData length]];
[request setURL:[NSURL URLWithString:#“WEBURL”]];
[request setHTTPMethod:#"POST"];
[request setValue:Length forHTTPHeaderField:#"Content-Length"];
[request setValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
}
// check connection if you want
/*****get response in delegates*******/
- (void)connection:(NSURLConnection *)connection didReceiveResponse:
(NSURLResponse *)response {
// A response has been received, this is where we initialize the instance var you created
// so that we can append data to it in the didReceiveData method
// Furthermore, this method is called each time there is a redirect so reinitializing it
// also serves to clear it
_responseData = [[NSMutableData alloc] init];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData*)data
{
/**************/
NSString* newStr = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSError* error;
NSDictionary* json = [NSJSONSerialization JSONObjectWithData:data
options:kNilOptions
error:&error];
// NSArray* latestLoans = [json objectForKey:#"loans"];
NSLog(#"json: %#", json);
[_responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(#"Error --> %#",error.localizedDescription);
/***************/
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *responseString = [[NSString alloc] initWithData:self.responseData encoding:NSUTF8StringEncoding];
NSError *error = nil;
id result = [NSJSONSerialization JSONObjectWithData:jsonData options:NSJSONReadingMutableContainers error:&error];
// use Result
self.responseData = nil;
}
I have a post method that looks like this:
NSString *totalPostURL = [NSString stringWithFormat:#"%#registerDevice",self.textUrl];
NSMutableURLRequest *request = [NSMutableURLRequest
requestWithURL:[NSURL URLWithString:totalPostURL]];
NSError *error;
NSData *postData = [NSJSONSerialization dataWithJSONObject:self.finalDict options:0 error:&error];
[request setValue:#"application/json" forHTTPHeaderField:#"Content-Type"];
[request setHTTPMethod:#"POST"];
[request setHTTPBody:postData];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
The code works fine but I have no idea how to print the response from this post. Any suggestions welcome as I'm new to iOS development.
You can print the response as below:
NSData *returnData = [ NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil ];
NSString *returnString = [[NSString alloc] initWithData:returnData encoding: NSUTF8StringEncoding];
NSLog(#"Response:%#",returnString);
But Remember as you are a newbie,don't forget to read the tutorial for calling webservices.Interacting with webservices.
You get your response in the connection delegate. Look for the method
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
// Append the new data to receivedData.
// receivedData is an instance variable declared elsewhere.
[receivedData appendData:data];
}
You can use like this...
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[receivedData appendData:data];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSString *jsonString = [[NSString alloc] initWithString: receivedData];
NSData* cData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
NSError *WSerror;
NSDictionary *responseDic = [NSJSONSerialization JSONObjectWithData:cData options:NSJSONReadingAllowFragments error:&WSerror];
}
Print the responseDic.
#Ayan Khan is right! here i'm adding sample code for http post print response and parsing as JSON if possible, it will handle everything async so your GUI will be refreshing just fine and will not freeze at all - which is important to notice.
//POST DATA
NSString *theBody = [NSString stringWithFormat:#"parameter=%#",YOUR_VAR_HERE];
NSData *bodyData = [theBody dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
//URL CONFIG
NSString *serverURL = #"https://your-website-here.com";
NSString *downloadUrl = [NSString stringWithFormat:#"%#/your-friendly-url-here/json",serverURL];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString: downloadUrl]];
//POST DATA SETUP
[request setHTTPMethod:#"POST"];
[request setHTTPBody:bodyData];
//DEBUG MESSAGE
NSLog(#"Trying to call ws %#",downloadUrl);
//EXEC CALL
[NSURLConnection sendAsynchronousRequest:request queue:[NSOperationQueue currentQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
if (error) {
NSLog(#"Download Error:%#",error.description);
}
if (data) {
//
// THIS CODE IS FOR PRINTING THE RESPONSE
//
NSString *returnString = [[NSString alloc] initWithData:data encoding: NSUTF8StringEncoding];
NSLog(#"Response:%#",returnString);
//PARSE JSON RESPONSE
NSDictionary *json_response = [NSJSONSerialization JSONObjectWithData:data
options:0
error:NULL];
if ( json_response ) {
if ( [json_response isKindOfClass:[NSDictionary class]] ) {
// do dictionary things
for ( NSString *key in [json_response allKeys] ) {
NSLog(#"%#: %#", key, json_response[key]);
}
}
else if ( [json_response isKindOfClass:[NSArray class]] ) {
NSLog(#"%#",json_response);
}
}
else {
NSLog(#"Error serializing JSON: %#", error);
NSLog(#"RAW RESPONSE: %#",data);
NSString *returnString2 = [[NSString alloc] initWithData:data encoding: NSUTF8StringEncoding];
NSLog(#"Response:%#",returnString2);
}
}
}];
Hope this helps!
I need to get a single value of JSON data from from four urls each. The code i've written to get JSON data from single url is
NSString *url=[NSString stringWithFormat:#"http://jsondata.in/UserImage.svc/GetUnAnsweredImagesLogCount?UserId=%#",requestString];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:[NSURL URLWithString:url]];
[request setHTTPMethod:#"GET"];
NSURLConnection * connReq = [[NSURLConnection alloc]initWithRequest:request delegate:self];
if (connReq) {
NSLog(#"Connection Sucessful");
receivedData = [[NSMutableData alloc]init];
[self facialimagelogcounturl];
}
else
{
NSLog(#"failed");
}
[connReq start];
NSHTTPURLResponse *response = nil;
NSError *error = nil;
NSData *respData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSLog(#"Status code: %ld", (long)[response statusCode]);
NSLog(#"respdata%#",respData);
-(void)connection:(NSURLConnection *)connection didReceiveResponse:
(NSURLResponse *)response
{
[receivedData setLength:0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:
(NSData *)data
{
[receivedData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
NSLog(#"ERROR");
}
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError *e;
NSString *JSON = [[NSString alloc] initWithData:self.receivedData encoding:NSUTF8StringEncoding];
_userlogcountlabel.text=JSON;
int json=[JSON intValue];
}
I need to display the data in different labels each for a url.For single getting single value from a single url its working fine. I need to make it for multiple urls.
Here is the answer for my own question.
NSString *url1=[NSString stringWithFormat:#"http://jsonddata.in/UserImage.svc/GetNotificationCount?UserId=%#&CategoryId=1",requestString];
NSURL *URL1 = [NSURL URLWithString:url1];
NSMutableURLRequest *request1 = [[NSMutableURLRequest alloc] initWithURL:URL1] ;
[NSURLConnection sendAsynchronousRequest:request1 queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSArray *results1 = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
NSLog(#"facialimage log count %#",[results1.firstObject objectForKey:#"Notifications"]);
}];
NSString *url2=[NSString stringWithFormat:#"http://jsonddata.in/UserImage.svc/GetNotificationCount?UserId=%#&CategoryId=2",requestString];
NSURL *URL2 = [NSURL URLWithString:url2];
NSMutableURLRequest *request2 = [[NSMutableURLRequest alloc] initWithURL:URL2] ;
[NSURLConnection sendAsynchronousRequest:request2 queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSArray *results1 = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
NSLog(#"clothing log count %#",[results1.firstObject objectForKey:#"Notifications"]);
}];
NSString *url3=[NSString stringWithFormat:#"http://jsondata.in/UserImage.svc/GetNotificationCount?UserId=%#&CategoryId=3",requestString];
NSURL *URL3 = [NSURL URLWithString:url3];
NSMutableURLRequest *request3 = [[NSMutableURLRequest alloc] initWithURL:URL3] ;
[NSURLConnection sendAsynchronousRequest:request3 queue:[NSOperationQueue mainQueue] completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
NSArray *results1 = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:nil];
NSLog(#"object compare log count %#",[results1.firstObject objectForKey:#"Notifications"]);
}
}];
I am making a synchronous call to the web service and sometimes I get the correct result back from the web service and sometimes I get HTML result indicating a Runtime error. Is there anything on the iOS side I have to do to correctly call the web service. Here is my code:
NSURLResponse *response = nil;
NSError *error = nil;
NSString *requestString = #"some parameters!";
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
[request addValue:#"application/x-www-form-urlencoded" forHTTPHeaderField:#"Content-Type"];
[request setHTTPMethod:#"POST"];
[request setHTTPBody:[requestString dataUsingEncoding:NSUTF8StringEncoding]];
NSData *data = [NSURLConnection sendSynchronousRequest:request
returningResponse:&response
error:&error];
NSString *responseData = [[NSString alloc] initWithData:data
encoding:NSUTF8StringEncoding];
Is it because I am not releasing properly?
you have to set the delegate methods of urlconnection like this
NSMutableURLRequest* urlRequest = [[NSMutableURLRequest alloc] initWithURL:url];
[urlRequest setHTTPMethod:#"POST"];
urLConnection=[[NSURLConnection alloc] initWithRequest:urlRequest delegate:self];
and the following delegate methods do the trick
- (void)connection:(NSURLConnection*)connection didReceiveResponse:(NSURLResponse*)response {
NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
[receivedData setLength:0];
}
-(void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
[receivedData appendData:data];
}
you will receive error in the following delegate if connection fails
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error{}
you better get the response from the finished connection which tells that all the data been received
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
recievedData //the complete data
}
try this
NSError * error;
NSURLResponse * urlresponse;
NSURL * posturl=[NSURL URLWithString:#"Type your webService URL here"];
NSMutableURLRequest * request=[[NSMutableURLRequest alloc]initWithURL:posturl cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:50];
[request setHTTPMethod:#"POST"];
[request addValue:#"application/x-www-form-urlencoded; charset=utf-8" forHTTPHeaderField:#"Content-Type"];
NSString * body=[NSString stringWithFormat:#"fbid=%#",userid];
[request setHTTPBody:[body dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]];
NSData * data=[NSURLConnection sendSynchronousRequest:request returningResponse:&urlresponse error:&error];
if (data==nil) {
return;
}
id jsonResponse=[NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];
NSLog(#" json response %#", jsonResponse);
if (![[jsonResponse objectForKey:#"code"] isEqualToNumber:[NSNumber numberWithInt:200]]) {
NSLog( #" successFull ");
this method works for me for more information read facebook documents for ios login
//set request
NSURLRequest *req=[NSURLRequest requestWithURL:[NSURL URLWithString:#"http://indianbloodbank.com/api/donors/?bloodgroup=O%2B"]];
NSLog(#"Request-%#",req);
NSError *err=nil;
NSURLResponse *res=nil;
NSData *xmldata=[NSURLConnection sendSynchronousRequest:req returningResponse:&res error:&err];
NSLog(#"Error-%#",err);
NSLog(#"Response-%#",res);
NSLog(#"XmlData-%#",xmldata);
xmldictionary=[XMLReader dictionaryForXMLData:xmldata error:&err];
NSLog(#"XmlDictionary-%#",xmldictionary);
mArray=[xmldictionary retrieveForPath:#"response.donorslist.donors"];
NSLog(#"MutableArray-%#",mArray);
lblname.text=[[mArray objectAtIndex:0]valueForKey:#"name"];
lbllocation.text=[[mArray objectAtIndex:0]valueForKey:#"location"];
lblphone.text=[[mArray objectAtIndex:0]valueForKey:#"phone"];
NSLog(#"%#,%#,%#",lblname.text,lbllocation.text,lblphone.text);
NSLog(#"%#",mArray);
For loop:
for (int i=0; i<mArray.count; i++)
{
Data * don=[NSEntityDescription insertNewObjectForEntityForName:#"Data" inManagedObjectContext:app.managedObjectContext];
don.donorid=[[mArray objectAtIndex:i]valueForKey:#"id"];
don.gender=[[mArray objectAtIndex:i]valueForKey:#"gender"];
don.name=[[mArray objectAtIndex:i]valueForKey:#"name"];
don.location=[[mArray objectAtIndex:i]valueForKey:#"location"];
don.phone=[[mArray objectAtIndex:i]valueForKey:#"phone"];
[app saveContext];
NSLog(#"%#,%#,%#,%#,%#",[[mArray objectAtIndex:i]valueForKey:#"id"],[[mArray objectAtIndex:i]valueForKey:#"gender"],[[mArray objectAtIndex:i]valueForKey:#"name"],[[mArray objectAtIndex:i]valueForKey:#"location"],[[mArray objectAtIndex:i]valueForKey:#"phone"]);
}