开发者

JSON touch iphone-sdk, send data over request

people, I'm using JSON touch inmy iphone app. Now I have to send a string and then an array to server, how can I do this? I get data from json requests succefully, but I have to send some data. Here is the code I've got so far:

-(void)subimtSelection:(int)aNumber
{
    NSString *choiceData=[NSString stringWithFormat:@"%d", aNumber];
    NSError *theError=nil;

    [[CJSONSerializer serializer] serializeString:choiceData error:&t开发者_运维知识库heError];
    NSDictionary *jsDic=[NSDictionary dictionaryWithObject:choiceData
                                                    forKey:@"selection"];
    //WHAT SHOULD I DO NEXT?


}


You can use ASIHTTRequest to POST string/json data to server:

    ASIHTTPRequest *request = [[ASIHTTPRequest alloc] initWithURL:@"http://server.url"];
    [request addRequestHeader:@"Accept" value:@"application/json"];
    [request addRequestHeader:@"Content-Type" value:@"application/json"];
    [request setRequestMethod:@"POST"];
    [request appendPostData:[yourJSONString dataUsingEncoding:NSUTF8StringEncoding]];
    [request startSynchronous];

If you want to post a string value then try:

[request appendPostData:@"key=value"];

ASIHTTPRequest can be used in asynchronious mode as well. P.S. I did not tested the code, but it should work.

To post form data you can use ASIFormDataRequest, documentation is here

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜