2013-07-28 78 views
0

我將Json數據發送到服務器時出現錯誤。我使用下面的代碼將NSMutableDictionary更改爲JSON。如何在post-request Objective-C中發送JSON數據?

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

JSON格式:

  {"user_email":"[email protected]","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. 
+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