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

Mockup & CodeGen, iPhone & iPad
($9.99)

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

Manu
($0.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, 01:05 AM   #1 (permalink)
Registered Member
 
Join Date: Mar 2010
Posts: 1
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, 04:49 AM   #2 (permalink)
Registered Member
 
Join Date: Jul 2010
Posts: 7
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, 04:17 PM   #3 (permalink)
Registered Member
 
Join Date: Jul 2010
Location: Texas
Posts: 40
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: 253
22 members and 231 guests
14DEV, @sandris, ADY, ArtieFufkin10, bookesp, ckgni, dacapo, Dani77, DarkAn, Davey555, Desert Diva, HemiMG, iDifferent, jakerocheleau, JasonR, prchn4christ, Rudy, ryantcb, Speed, theone8one
Most users ever online was 1,187, 10-11-2011 at 08:09 AM.
» Stats
Members: 158,885
Threads: 89,230
Posts: 380,766
Top Poster: BrianSlick (7,129)
Welcome to our newest member, bookesp
Powered by vBadvanced CMPS v3.1.0

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