Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 03-14-2010, 12:05 AM   #1 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 1
nikh_18_1 is on a distinguished road
Default For Json parsing using http post request

I am trying to parse jason using http post method and json request but this got html output. so please help me how can i parse jason request and got correct output.





NSString * urlString = [NSString stringWithFormat:@"http://184.73.218.222:8080/setuka/rest/api/registerDevice"];
NSLog(@"urlString: - %@",urlString);
NSURL * URL = [NSURL URLWithString:urlString];
NSString * requestBody = [NSString stringWithFormat:@"{\"deviceId\":\"SDFFASFASDFASFA DSFASDFADSFASDFASD\",\"loc\":{\"latitude\":\"37.52 0777\",\"longitude\":\"-122.252559\"},\"mobileNo\":\"973-443-0484\",\"type\":\"type1\"}"];
NSLog(@"------------REQUESTBODY=%@---------------",requestBody);
NSMutableURLRequest * serverRequest = [NSMutableURLRequest requestWithURL:URL];
[serverRequest setHTTPMethod:@"POST"];
[serverRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[serverRequest setHTTPBody:[requestBody dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES]];
[serverRequest setValue:[NSString stringWithFormat:@"%d",[requestBody length] ] forHTTPHeaderField:@"Content-Length"];
NSData * returnData = [NSURLConnection sendSynchronousRequest:serverRequest returningResponse:nil error:nil];
NSString * returnString = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSLog(@"json string =%@",returnString);
NSMutableArray * array = [returnString JSONValue];
NSString * login = [array valueForKey:@"login"];
NSLog(@"login :",login);


Thanks.
nikh_18_1 is offline   Reply With Quote
Old 09-27-2010, 03:49 AM   #2 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 7
sambasivarao4u is on a distinguished road
Default JSON Request over Http Post

NSData *topImageData = UIImageJPEGRepresentation(pickedImage, 1.0);
NSString *myString=[NSString stringWithFormat:@"%@",topImageData];

NSArray *keysArray=[NSArray arrayWithObjects:@"transactionId",@"image",nil];
NSArray *objectsArray=[NSArray arrayWithObjects:@"1",myString,nil];

NSDictionary *theRequestDictionary=[[[NSDictionary alloc] initWithObjectsbjectsArray forKeys:keysArray] autorelease];

NSArray *keysArray1=[NSArray arrayWithObjects:@"transactions",nil];
NSArray *objectsArray1=[NSArray arrayWithObjects:theRequestDictionary,nil];

NSDictionary *myRequestDictionary=[[NSDictionary alloc] initWithObjectsbjectsArray1 forKeys:keysArray1];

NSURL *theURL = [NSURL URLWithString:@"http://10.10.39.92:8080/taxdeductableproductfinder/calculator/tax/image"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:theURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10.0f];
[theRequest setHTTPMethod:@"POST"];

[theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSString *theBodyString = [[CJSONSerializer serializer] serializeDictionary:myRequestDictionary];
NSString *appendedBodyString=[NSString stringWithFormat:@"analysisRequest={\"productFinde rRequest\":%@}",theBodyString];
NSLog(@"Request in JSON Format ->%@", appendedBodyString);
NSData *theBodyData = [appendedBodyString dataUsingEncoding:NSUTF8StringEncoding];
//NSLog(@"Request Body-->%@", theBodyData);
[theRequest setHTTPBody:theBodyData];

NSURLResponse *theResponse = NULL;
NSError *theError = NULL;
NSData *theResponseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&theResponse error:&theError];
NSLog(@"response data %@",theResponseData);
sambasivarao4u is offline   Reply With Quote
Old 12-01-2010, 03:17 PM   #3 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: Texas
Posts: 40
ronbowalker is on a distinguished road
Default

Quote:
Originally Posted by sambasivarao4u View Post
NSData *topImageData = UIImageJPEGRepresentation(pickedImage, 1.0);
NSString *myString=[NSString stringWithFormat:@"%@",topImageData];

NSArray *keysArray=[NSArray arrayWithObjects:@"transactionId",@"image",nil];
NSArray *objectsArray=[NSArray arrayWithObjects:@"1",myString,nil];

NSDictionary *theRequestDictionary=[[[NSDictionary alloc] initWithObjectsbjectsArray forKeys:keysArray] autorelease];

NSArray *keysArray1=[NSArray arrayWithObjects:@"transactions",nil];
NSArray *objectsArray1=[NSArray arrayWithObjects:theRequestDictionary,nil];

NSDictionary *myRequestDictionary=[[NSDictionary alloc] initWithObjectsbjectsArray1 forKeys:keysArray1];

NSURL *theURL = [NSURL URLWithString:@"http://10.10.39.92:8080/taxdeductableproductfinder/calculator/tax/image"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:theURL cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval:10.0f];
[theRequest setHTTPMethod:@"POST"];

[theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSString *theBodyString = [[CJSONSerializer serializer] serializeDictionary:myRequestDictionary];
NSString *appendedBodyString=[NSString stringWithFormat:@"analysisRequest={\"productFinde rRequest\":%@}",theBodyString];
NSLog(@"Request in JSON Format ->%@", appendedBodyString);
NSData *theBodyData = [appendedBodyString dataUsingEncoding:NSUTF8StringEncoding];
//NSLog(@"Request Body-->%@", theBodyData);
[theRequest setHTTPBody:theBodyData];

NSURLResponse *theResponse = NULL;
NSError *theError = NULL;
NSData *theResponseData = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&theResponse error:&theError];
NSLog(@"response data %@",theResponseData);
I need some help with JSON process. Can you PM me so we can talk more?
ronbowalker is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 424
15 members and 409 guests
AppsImpact, AReality, BSH, Cee Oasis, djqbert, Duncan C, epaga, flamingliquid, HemiMG, jbro, leighec68, nobstudio, revg, Rudy, taylor202
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,645
Threads: 94,111
Posts: 402,862
Top Poster: BrianSlick (7,990)
Welcome to our newest member, leighec68
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 05:12 PM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0