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 10-14-2011, 02:33 AM   #1 (permalink)
Registered Member
 
Join Date: Oct 2011
Posts: 2
Stahilov_v is on a distinguished road
Default Retrieve a data sent as JSON from iphone-sdk

I make a json string and then send it to server as data with ASIHTTPRequest, but my request arrives as empty array to server, could you please help me? how to send a valid data to server? Here is my code:
-(void)subimtSelectionint)selection
{
NSLog(@"Submiting selection");
NSString *choiceData=[NSString stringWithFormat:@"%d", selection];

NSError *theError=nil;
NSURL *myUrl=[NSURL URLWithString:@"http://q.crazyteabag.com/get_data.php"];
//[[CJSONSerializer serializer] serializeString:choiceData error:&theError];
NSMutableDictionary *requestDictionary=[[NSMutableDictionary alloc] init];
[requestDictionary setObject:choiceData forKey:@"data"];
//NSData *data=[[CJSONSerializer serializer] serializeArray:requestArray error:&theError];
//NSData *data=[[CJSONSerializer serializer] serializeDictionary:requestDictionary error:&theError];
NSString *jsonString=[requestDictionary JSONRepresentation];
//NSData *data=[[CJSONSerializer serializer] serializeString:choiceData error:&theError];


ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:myUrl];
[request addRequestHeader:@"Accept" value:@"application/json"];
[request addRequestHeader:@"Content-Type" value:@"application/json"];
[request setRequestMethod:@"POST"];
[request appendPostData:[jsonString dataUsingEncoding:NSUTF8StringEncoding]];

[request start];
//request.delegate=self;
NSLog(@"Data %@",jsonString);
NSLog(@"The Error: %@", theError);


}
Stahilov_v is offline   Reply With Quote
Old 10-14-2011, 04:00 AM   #2 (permalink)
Registered Member
 
Join Date: Sep 2011
Location: delhi
Posts: 19
IphoneIndia is on a distinguished road
Default try this

move ur POST method before ur Request
and instead making Request in array, convert ur request data in string and create request for string than sent dat to server u will get response.
IphoneIndia is offline   Reply With Quote
Reply

Bookmarks

Tags
iphone-sdk, json, objective-c

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: 405
16 members and 389 guests
13dario13, 7twenty7, buggen, eski, EvilElf, glenn_sayers, LunarMoon, morterbaher, n00b, pbart, QuantumDoja, sacha1996, Sami Gh, UMAD, VinceYuan
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,673
Threads: 94,122
Posts: 402,906
Top Poster: BrianSlick (7,990)
Welcome to our newest member, morterbaher
Powered by vBadvanced CMPS v3.1.0

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