Urban Airship - Send Push with NSURLConnection - objective-c

I'm working on a simple prototype and need to test sending push notifications from one device to another.
I've emailed Urban Airship to turn on the "Allow Push From Device" for my application - and they did turn it on.
I'm trying to use NSURLConnection to send the push notification from the device.
This is my code:
- (void) test {
NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:#"https://go.urbanairship.com/api/push"]];
[request setHTTPMethod:#"POST"];
[request setValue:#"application/json" forHTTPHeaderField:#"Content-Type"];
NSDictionary * push = #{#"device_tokens":#[#"<token>"], #"aps":#{#"alert":#"TEST", #"sound":#"default"}};
NSData * pushdata = [NSJSONSerialization dataWithJSONObject:push options:0 error:NULL];
[request setHTTPBody:pushdata];
[NSURLConnection connectionWithRequest:request delegate:self];
}
- (void) connection:(NSURLConnection *) connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *) challenge {
if([challenge.protectionSpace.authenticationMethod isEqualToString:NSURLAuthenticationMethodHTTPBasic]) {
NSURLCredential * credential = [[NSURLCredential alloc] initWithUser:#"<app key>" password:#"<app secret>" persistence:NSURLCredentialPersistenceForSession];
[[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
[credential release];
}
}
- (void) connection:(NSURLConnection *) connection didReceiveResponse:(NSURLResponse *) response {
NSHTTPURLResponse * res = (NSHTTPURLResponse *) response;
NSLog(#"response: %#",res);
NSLog(#"res %i\n",res.statusCode);
}
Anyone else done this successfully?

Taking a look at Urban Airship's guide to troubleshooting HTTP status codes, and the documentation for the push API, my guess would be that you need to add a trailing slash to the URL:
[NSURL URLWithString:#"https://go.urbanairship.com/api/push/"]

Example Using the V3 API...
-(void)richPushNotification{
NSDictionary *push = #{
#"audience" : #{
#"device_token" : deviceToken
},
#"device_types" : #[ #"ios" ],
#"notification" : #{
#"ios" : #{
#"alert":Message,
#"sound":#"default",
#"badge":#"auto",
}
},
#"message": #{
#"title": Message,
#"body": #"<html><body><h1>blah blah</h1> etc...</html>",
#"content_type": #"text/html",
#"extra": #{
#"offer_id" : #"608f1f6c-8860-c617-a803-b187b491568e"
}
}
};
NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:#"https://go.urbanairship.com/api/push/"]];
[request setHTTPMethod:#"POST"];
[request setValue:#"application/json" forHTTPHeaderField:#"Content-Type"];
[request setValue:#"application/vnd.urbanairship+json; version=3;" forHTTPHeaderField:#"Accept"];
NSString *authStr = [NSString stringWithFormat:#"%#:%#", appKey, appMasterSecret];
NSData *authData = [authStr dataUsingEncoding:NSASCIIStringEncoding];
NSString *authValue = [NSString stringWithFormat:#"Basic %#", [authData base64EncodedStringWithOptions:NSDataBase64EncodingEndLineWithLineFeed]];
[request setValue:authValue forHTTPHeaderField:#"Authorization"];
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:push
options:0 // Pass 0 if you don't care about the readability of the generated string
error:NULL];
request.HTTPBody = jsonData;
[NSURLConnection connectionWithRequest:request delegate:self];
}
And The Response:
- (void) connection:(NSURLConnection *) connection didReceiveResponse:(NSURLResponse *) response {
NSHTTPURLResponse * res = (NSHTTPURLResponse *) response;
NSLog(#"response: %#",res);
NSLog(#"res %li\n",(long)res.statusCode);
if (res.statusCode == 202) {
//Show Alert Message Sent
}else{
//Handle Error
}
}

Related

How to create and post json to web service Objective c

I try to convertNSDictionary to JSON data and sent it to PHP.server in "POST" request with setHTTPBody.
I received a null from the server when I sent from my app, but when I send the JSON from PostMan I receive the objects.
Where am I wrong ?
- (void)viewDidLoad
{
[super viewDidLoad];
NSError *error = nil;
NSString *url = [NSString stringWithFormat:#"http://myAddress/sql_service.php"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
[request setHTTPMethod:#"POST"];
[request setValue:#"application/json" forHTTPHeaderField:#"Content-Type"];
[request setValue:#"application/json" forHTTPHeaderField:#"Accept"];
NSArray *arrayOfStrings = #[#"alex",#"dima"];
NSDictionary *dict = #{#"request_type" : #"select_with_params",
#"table" : #"user",
#"where" : #"f_name=? OR f_name=?",
#"values" : arrayOfStrings};
NSData* jsonData1 = [NSJSONSerialization dataWithJSONObject:dict options:kNilOptions error:&error];
[request setHTTPBody:jsonData1];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
[connection start];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
if (data)
{
[receivedData appendData:data];
}
else
{
}
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
{
NSLog(#"didFailWithError");
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSError * error = nil;
NSMutableDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:receivedData options:0 error:&error];
NSLog(#"connectionDidFinishLoading");
}
this is the json i need to post.
{
request_type: "select_with_params",
table: "user",
where: "f_name=? OR f_name=?",
values: ["dima", "alex"]
}
jsonData1 is not nil.
the data in didReceiveData is :
Try AFNetworking
EDIT
NSString *url = [NSString stringWithFormat:#"http://myAddress/sql_service.php"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
[request setHTTPMethod:#"POST"];
[request setValue:#"application/json" forHTTPHeaderField:#"Content-Type"];
[request setValue:#"application/json" forHTTPHeaderField:#"Accept"];
NSArray *arrayOfStrings = #[#"alex",#"dima"];
NSDictionary *dict = #{#"request_type" : #"select_with_params",
#"table" : #"user",
#"where" : #"f_name=? OR f_name=?",
#"values" : arrayOfStrings};
NSData* jsonData1 = [NSJSONSerialization dataWithJSONObject:dict options:kNilOptions error:&error];
[request setHTTPBody: [[NSString stringWithFormat:#"%#", jsonData1] dataUsingEncoding:NSUTF8StringEncoding]];
AFHTTPRequestOperation *op = [[AFHTTPRequestOperation alloc] initWithRequest:request];
op.responseSerializer = [AFJSONResponseSerializer serializer];
[op setCompletionBlockWithSuccess:^(AFHTTPRequestOperation *operation, id responseObject){
if (responseObject)
{
NSLog(#"Success!");
}} failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSLog(#"Error");
}];
[op start];
Hope this helps

Translating cURL request to NSMutableURLRequest

I'm a new Objective-C developer and I'm interacting with an API in the cURL format. I'm used to making calls using URLs, so I pieced together a request from what I found on the internets. I'm still not able to pull the data in my app.
This is the original cURL request (with dummy keys of course):
curl -v -H "app_id:12345" -H "app_key:abcdefg" -X POST "http://data.host.com/object" -d '{"Page":0,"Take":10}'
This is my attempt:
//Request
NSURLSession *session = [NSURLSession sharedSession];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:#"http://data.host.com/object"]];
//Set method
request.HTTPMethod = #"POST";
//Set parameters
NSDictionary *parameters = #{
#"Page": #(0),
#"Take": #(10)
};
NSMutableString *parameterString = [NSMutableString string];
for (NSString *key in [parameters allKeys]) {
if ([parameterString length]) {
[parameterString appendString:#"&"];
}
[parameterString appendFormat:#"%#=%#", key, parameters[key]];
}
NSLog(#"PARAMETER STRING: %#",parameterString);
//Set headers
[request setValue:#"12345" forHTTPHeaderField:#"app_id"];
[request setValue:#"abcdefg" forHTTPHeaderField:#"app_key"];
[request setHTTPBody:[parameterString dataUsingEncoding:NSUTF8StringEncoding]];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:^(NSData *data, NSURLResponse *response, NSError *error) {
if (!error) {
if ([data length]) {
NSDictionary *jsonResponse = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(#"JSON RESPONSE: %#", jsonResponse);
}
} else {
NSLog(#"%#", error);
}
}];
[task resume];
NSLog(#"TASK: %#", task);
I don't get an error, but the jsonResponse returns NULL. Anybody have an idea on what I'm missing? Thanks in advance!
You would see the difference if you compared the HTTP message exchanges between the curl version and your obj-c version. AFAICS you're missing a header for content type where you specify the encoding of the body. When posting you need to pass information on how you are encoding the body.
Here is some example code from one of my apps:
- (NSURLRequest *)createPostRequestWithURL:(NSURL *)url
parameters:(NSDictionary *)parameters {
NSLog(#"startGetTaskForUrl: %#, params %#", url, parameters);
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:#"POST"];
[request addValue:#"application/x-www-form-urlencoded"
forHTTPHeaderField:#"Content-Type"];
NSString * httpParams = [self createHttpParameters:parameters];
NSLog(#"HTTPClient: postRequestWithURL body: %#", httpParams);
[request setHTTPBody:[httpParams dataUsingEncoding:NSUTF8StringEncoding]];
return request;
}
- (NSString *)urlEncodedUTF8String: (NSString *) source {
return (id)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(0, (CFStringRef)source, 0,
(CFStringRef)#";/?:#&=$+{}<>,", kCFStringEncodingUTF8));
}
- (NSString *) createHttpParameters: (NSDictionary *) parameters {
NSMutableString *body = [NSMutableString string];
for (NSString *key in parameters) {
NSString *val = [parameters objectForKey:key];
if ([body length])
[body appendString:#"&"];
[body appendFormat:#"%#=%#", [self urlEncodedUTF8String: [key description]],
[self urlEncodedUTF8String: [val description]]];
}
return body;
}

iOs receivedData from NSURLConnection is nil

I was wondering if anyone could point out why I'm not able to capture a web reply. My NSLog shows that my [NSMutableData receivedData] has a length of 0 the entire run of the connection. The script that I hit when I click my login button returns a string. My NSLog result is pasted below, and after that I've pasted both the .h and .m files that I have.
NSLog Result
2012-11-28 23:35:22.083 [12548:c07] Clicked on button_login
2012-11-28 23:35:22.090 [12548:c07] theConnection is succesful
2012-11-28 23:35:22.289 [12548:c07] didReceiveResponse
2012-11-28 23:35:22.290 [12548:c07] didReceiveData
2012-11-28 23:35:22.290 [12548:c07] 0
2012-11-28 23:35:22.290 [12548:c07] connectionDidFinishLoading
2012-11-28 23:35:22.290 [12548:c07] 0
ViewController.h
#import <UIKit/UIKit.h>
#interface ViewController : UIViewController
// Create an Action for the button.
- (IBAction)button_login:(id)sender;
// Add property declaration.
#property (nonatomic,assign) NSMutableData *receivedData;
#end
ViewController.m
#import ViewController.h
#interface ViewController ()
#end
#implementation ViewController
#synthesize receivedData;
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSLog(#"didReceiveResponse");
[receivedData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
NSLog(#"didReceiveData");
[receivedData appendData:data];
NSLog(#"%d",[receivedData length]);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSLog(#"connectionDidFinishLoading");
NSLog(#"%d",[receivedData length]);
}
- (IBAction)button_login:(id)sender {
NSLog(#"Clicked on button_login");
NSString *loginScriptURL = [NSString stringWithFormat:#"http://www.website.com/app/scripts/login.php?"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:loginScriptURL]];
NSString *postString = [NSString stringWithFormat:#"&paramUsername=user&paramPassword=pass"];
NSData *postData = [postString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
[theRequest setHTTPMethod:#"POST"];
[theRequest setHTTPBody:postData];
// Create the actual connection using the request.
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
// Capture the response
if (theConnection) {
NSLog(#"theConnection is succesful");
} else {
NSLog(#"theConnection failed");
}
}
#end
The issue is you are not initializing the receivedData instance. Just change your property like:
#property (nonatomic, retain) NSMutableData *receivedData;
And change the methods like:
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
NSLog(#"didReceiveResponse");
[self.receivedData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data
{
NSLog(#"didReceiveData");
[self.receivedData appendData:data];
NSLog(#"%d",[receivedData length]);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection
{
NSLog(#"connectionDidFinishLoading");
NSLog(#"%d",[receivedData length]);
}
- (IBAction)button_login:(id)sender
{
NSLog(#"Clicked on button_login");
NSString *loginScriptURL = [NSString stringWithFormat:#"http://www.website.com/app/scripts/login.php?"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:loginScriptURL]];
NSString *postString = [NSString stringWithFormat:#"&paramUsername=user&paramPassword=pass"];
NSData *postData = [postString dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
[theRequest setHTTPMethod:#"POST"];
[theRequest setHTTPBody:postData];
// Create the actual connection using the request.
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
// Capture the response
if (theConnection)
{
NSLog(#"theConnection is succesful");
self.receivedData = [NSMutableData data];
} else
{
NSLog(#"theConnection failed");
}
}
Please try "%i" instead of %d in nslog
You can try the following code May be help you.
- (IBAction)button_login:(id)sender {
NSLog(#"Clicked on button_login");
NSMutableDictionary *dictionnary = [NSMutableDictionary dictionary];
[dictionnary setObject:#"user" forKey:#"Username"];
[dictionnary setObject:#"pass" forKey:#"Password"];
NSError *error = nil;
NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictionnary
options:kNilOptions
error:&error];
NSString *urlString = #"Sample URL";
NSURL *url = [NSURL URLWithString:urlString];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:#"POST"];
[request setHTTPBody:jsonData];
NSURLResponse *response = NULL;
NSError *requestError = NULL;
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&requestError];
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding] ;
NSLog(#"%#", responseString);
}
if it is a GET Request then, can you try link : /login.php?username=admin&password=1212‌​3
- (IBAction)button_login:(id)sender {
NSLog(#"Clicked on button_login");
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:#"/login.php?username=adm‌​in&password=1212‌​3"]];
// Perform request and get JSON as a NSData object
NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
NSLog(#"response=%#",response );
}
and use this code.

HTTP request objective c

I am trying to make a HTTP request in this way:
NSString *urlString = [NSString stringWithFormat:#"https://api.dropbox.com/1/oauth/request_token"];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:urlString]];
[request setHTTPMethod:#"POST"];
//set headers
NSString *contentType = [NSString stringWithFormat:#"text/xml"];
[request addValue:contentType forHTTPHeaderField: #"Content-Type"];
oauth_version="1.0"
oauth_signature_method="PLAINTEXT"
oauth_consumer_key="<app-key>"
oauth_signature="<app-secret>&"
//create the body
NSMutableData *postBody = [NSMutableData data];
[postBody appendData:[[NSString stringWithFormat:#"<xml>"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:#"<yourcode/>"] dataUsingEncoding:NSUTF8StringEncoding]];
[postBody appendData:[[NSString stringWithFormat:#"</xml>"] dataUsingEncoding:NSUTF8StringEncoding]];
//post
[request setHTTPBody:postBody];
//get response
NSHTTPURLResponse* urlResponse = nil;
NSError *error = [[NSError alloc] init];
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSLog(#"Response Code: %d", [urlResponse statusCode]);
if ([urlResponse statusCode] >= 200 && [urlResponse statusCode] < 300) {
NSLog(#"Response: %#", result);
//here you get the response
}
I am trying to make the request with these headers:
Authorization: OAuth oauth_version="1.0", oauth_signature_method="PLAINTEXT", oauth_consumer_key="<app-key>", oauth_signature="<app-secret>&"
But I can't understand how to. PLease help!!
The authorization in your case is just a HTTP header. So it's:
[request addValue:#"OAuth oauth_version=\"1.0\", oauth_signature_method=\"PLAINTEXT\", oauth_consumer_key=\"<app-key>\", oauth_signature=\"<app-secret>&\"" forHTTPHeaderField: #"Authorization"];
Or:
NSString* oauth_version=#"1.0";
NSString* oauth_signature_method=#"PLAINTEXT";
NSString* oauth_consumer_key=#"<app-key>";
NSString* oauth_signature=#"<app-secret>&";
NSString* authHeader = [NSString stringWithFormat: #"OAuth oauth_version=\"%#\", oauth_signature_method=\"%#\", oauth_consumer_key=\"%#\", oauth_signature=\"%#\"",
oauth_version, oauth_signature_method, oauth_consumer_key, oauth_signature];
Try commenting all this
//NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&urlResponse error:&error];
//NSString *result = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
//NSLog(#"Response Code: %d", [urlResponse statusCode]);
//if ([urlResponse statusCode] >= 200 && [urlResponse statusCode] < 300) {
// NSLog(#"Response: %#", result);
//here you get the response
//}
and use this instead of all above
NSURLConnection *conn = [NSURLConnection connectionWithRequest:request delegate:self];
Implement these delegate functions
Note - self.data is NSMUtableData object declared as data in header.
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
[self.data setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)d {
[self.data appendData:d];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
[[[[UIAlertView alloc] initWithTitle:NSLocalizedString(#"Error", #"")
message:[error localizedDescription]
delegate:nil
cancelButtonTitle:NSLocalizedString(#"OK", #"")
otherButtonTitles:nil] autorelease] show];
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
NSString *responseText = [[NSString alloc] initWithData:self.data encoding:NSUTF8StringEncoding];
// Do anything you want with it
[responseText release];
}
// Handle basic authentication challenge if needed
- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
//I'm using HTTP Digest Authentication in your case it could be different
NSURLCredential *credential = [NSURLCredential credentialWithUser:HTTP_DIGEST_USER
password:HTTP_DIGEST_PASSWORD
persistence:NSURLCredentialPersistenceForSession];
[[challenge sender] useCredential:credential forAuthenticationChallenge:challenge];
}
Hope it will help
This error occurs when your are passing wrong bundle or document directory path to media.
Just simply verify your media path to the HTTP request body.

How do make Json request to server?

I'm doing an application that should work with the server.
Need to be authorized on the server through the program using the username and password.
I need to make a request to the server with the line:
{"login": "mad_fashist", "password": "eqeeuq313371", "method": "authentificator"}
The string must be in Json.
In response, I should get a line if authentication fails:
{"validated": "false", "kuid": "", "sid": "", "uid": ""}
And if authentication is passed:
{"validated":"true","kuid":"6","sid":"834fe9b4626502bf9ff23485a408ac40","uid":"69"}
The question is how to send and receive all of the above?
Use SBJson framework. and do smth like:
-(void)requestProjects
{
//I prepare the string
NSString *preparedString=[NSString stringWithFormat:#"%# %#", self.lastDate, self.currentCategory];
NSDictionary *jsonDict = [NSDictionary dictionaryWithObject:preparedString forKey:#"request"];
//Prepare convert to json string
NSString *jsonRequest = [jsonDict JSONRepresentation];
NSLog(#"jsonRequest is %#", jsonRequest);
//Set the URL YOU WILL PROVIDE
NSURL *url = [NSURL URLWithString:#"http:xxxxxxxxxxxxxxxxxxx"];
//PREPARE the request
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
//Prepare data which will contain the json request string.
NSData *requestData = [NSData dataWithBytes:[jsonRequest UTF8String] length:[jsonRequest length]];
//Set the propreties of the request
[request setHTTPMethod:#"POST"];
[request setValue:#"application/json" forHTTPHeaderField:#"Accept"];
[request setValue:#"application/json" forHTTPHeaderField:#"Content-Type"];
[request setValue:[NSString stringWithFormat:#"%d", [requestData length]] forHTTPHeaderField:#"Content-Length"];
[request setValue:jsonRequest forHTTPHeaderField:#"Query-string"];
//set the data prepared
[request setHTTPBody: requestData];
//Initialize the connection with request
NSURLConnection *connection = [[NSURLConnection alloc]initWithRequest:request delegate:self];
//Start the connection
[delegate showIndicator];
[connection start];
}
//delegate methods:
//METHODS TO HANßDLE RESPONSE
#pragma mark NSURLConnection delegate methods
//WHen receiving the response
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response {
NSLog(#" Did receive respone");
[responseData setLength:0];
}
- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {
//While receiving the response data
[responseData appendData:data];
}
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
//When failed just log
[delegate hideIndicator];
NSLog(#"Connection failed!");
NSLog(#"Error %#", error);
}
- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
//When the response data is downloaded
// NSLog(#" Data obtained %#", responseData);
NSString *responseString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
// NSLog(#" Response String %#", responseString);
//converted response json string to a simple NSdictionary
//If the response string is really JSONABLE I will have the data u sent me displayed succefully
NSMutableArray *results = [responseString JSONValue];
NSLog(#"Response: %#", results);
/// la la al alal alaa
}
It's your back end who should define how the response in Json will look like
Refer NSJsonSerialization class. Which is newly included in ios5.0. which is the most flexible one for your need. you can access it in apple developer site.
link to NSJSONSerialization