如何在post request Objective-C中发送JSON数据?

时间:2013-07-28 14:19:15

标签: objective-c json

我将Json数据发送到服务器时出错。我使用以下代码将NSMutableDictionary更改为JSON。

NSString* jsonString1 = [postDict JSONRepresentation];
NSLog(@"%@",jsonString1); 

JSON格式:

         {"user_email":"gupta.nivrit@gmail.com","firstname":"nivrit","user_password":"1234","confirm_passward":"1234"}

我使用以下方法将此JSON格式发送到服务器:

NSMutableDictionary *responseDict = 
    (NSMutableDictionary *)[[mWebServiceHelperOBJ 
              makeCallToURL:@"register.php" 
              withDataPost:jsonString1] JSONValue];

当我实现此代码时,我收到了此问题

incompatible pointer type sending  NSString to parameter of type  NSMutableDictionary.

1 个答案:

答案 0 :(得分:1)

如果你的方法

- (NSString *)makeCallToURL:(NSString*)url withDataPost:(NSMutableDictionary*)dict;

与此问题相同:Uploading PDF file through JSON Web Service,然后请求数据的JSON编码在内部完成 那个方法,所以你应该直接用postDict来调用它, 而不是使用JSON字符串jsonString1

NSMutableDictionary *responseDict = 
    (NSMutableDictionary *)[[mWebServiceHelperOBJ makeCallToURL:@"register.php" 
                                                   withDataPost:postDict] JSONValue];

(这假设postDictNSMutableDictionary。)

相关问题