2017-02-17 3 views
2

私はNSMutableDictionaryをAFNetworkingフレームワークを使用してリクエストに送信するように構築しようとしていますが、正しく行う方法についてはかなり混乱しているようです。ここでAFNetworking - NSMutableDictionaryパラメータ

は、サーバーが

{ 
"do":"timeline", 
"what":"posting", 
"session":"", 
"data":{ 
"status_timeline":"", 
    "with_timeline":"", 
    "location_timeline":"", 
    "category_timeline":"", 
    "privacy_timeline":"" 
} 

を期待していると私は私が誰かが私にあなたがどのような入力を取得するには、以下を使用することができ感謝の

+0

ようこそ。これは「あなたはxyzをやる方法」に関する2番目の質問です。これはチュートリアルサイトではなく、問題を特定する必要があります。これまでに試したこと、得られた結果、実行しているエラー、期待していたこと、必要な特定の問題に関する特定の質問解決する。フラグを避けるためにさらに質問を投稿する前に、http://stackoverflow.com/help/how-to-askを読んでください。あなたが達成しようとしているものには、複数のスレッドがあります。例:http://stackoverflow.com/questions/34434728/how-to-post-json-parameters-using-afnetworking –

答えて

0

を助けることを願って、この

NSMutableDictionary *dict = [[NSMutableDictionary alloc]init]; 
    [dict setValue:@"timeline" forKey:@"do"]; 
    [dict setValue:@"posting" forKey:@"what"]; 
    [dict setValue:session forKey:@"session"]; 
    NSLog(@"Session %@", [dict valueForKey:@"session"]); 

ようにしようとしたものですあなたのサーバーが必要です。サーバーがデータ辞書からデコードすることを確認します。

NSMutableDictionary *dicData = [NSMutableDictionary new]; 
    dicData[@"status_timeline"] = @""; 
    dicData[@"with_timeline"] = @""; 
    dicData[@"location_timeline"] = @""; 
    dicData[@"category_timeline"] = @""; 
    dicData[@"privacy_timeline"] = @""; 
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dicData options:NSJSONWritingPrettyPrinted error:nil]; 
    NSString *jsonString = [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding]; 


    NSMutableDictionary *dict = [[NSMutableDictionary alloc]init]; 
    [dict setValue:@"timeline" forKey:@"do"]; 
    [dict setValue:@"posting" forKey:@"what"]; 
    [dict setValue:@"" forKey:@"session"]; 
    [dict setValue:jsonString forKey:@"data"]; 
    NSLog(@"Your Main Dic: %@", dict); 
+0

ありがとうございますが、辞書はサーバーに送信されません –

+0

辞書をJSONオブジェクト(文字列)に変換し、jsonをサーバーに渡します。だから、サーバーのチェックを入れて、問題は解決されます。 – Nirmalsinh

+0

これは完全に機能しました。どうもありがとう! –

関連する問題