2012-10-26 189 views
0
I am sending a dict with objects 
//Check n/w status 
if ([Helper checkNetworkStatus]) { 
    NSMutableDictionary *dict = [[NSMutableDictionary alloc] init]; 
    [dict setObject:self.mEmailAddress.text forKey:@"emailaddress"]; 
    [dict setObject:self.mNameTextField.text forKey:@"firstname"]; 
    [dict setObject:self.mPhoneNumber.text forKey:@"lastname"]; 
    [dict setObject:self.mTextView.text forKey:@"notes"]; 
    [dict setObject:[NSData dataWithContentsOfFile:self.mPdfPath] forKey:@"uploadedfile"]; 
    NSLog(@"The Data is %@",dict); 

    WebServiceHelper *mWebServiceHelperOBJ = [[WebServiceHelper alloc]init]; 

    // Posting Data Url 
    NSMutableArray *responseDict = (NSMutableArray *)[[mWebServiceHelperOBJ makeCallToURL:@"test.php" withDataPost:dict] JSONValue]; 
    NSLog(@" The response Dict is%@",responseDict); 

    if ([[responseDict valueForKey:@"JsonObject"] isEqualToString:@"DEFAULT_VALUE"]) 
    { 
     [Helper showAlert:@"Message" withMessage:@"Data posted successfully"]; 
    } 
} 



//Postind data & reponse 
- (NSString *)makeCallToURL:(NSString*)url withDataPost:(NSMutableDictionary*)dict { 

NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:[[NSString stringWithFormat:@"%@%@",kURL,url] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]]; 
[urlRequest setTimeoutInterval:180]; 

NSString *requestBody = [NSString stringWithFormat:@"JsonObject=%@", [dict JSONRepresentation]]; 

[urlRequest setHTTPBody:[requestBody dataUsingEncoding:NSUTF8StringEncoding]]; 
    // [urlRequest setValue:@"application/json" forHTTPHeaderField:@"content-type"]; 
[urlRequest setHTTPMethod:@"POST"]; 

NSURLResponse *response; 
NSError *error; 
NSData *responseData = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error] ; 

if([responseData length]) 
{ 
    NSString *data = [[[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding] autorelease];  
    return data; 
} 
return nil; 

}上传PDF文件

but the request Body represent an error.. 

    PDFGenerator[1000:1c103] -JSONRepresentation failed. Error trace is: (
"Error Domain=org.brautaset.JSON.ErrorDomain Code=1 \"JSON serialisation not supported for NSConcreteData\" UserInfo=0xb178d50 {NSLocalizedDescription=JSON serialisation not supported for NSConcreteData}", 
"Error Domain=org.brautaset.JSON.ErrorDomain Code=1 \"Unsupported value for key uploadedfile in object\" UserInfo=0xb107430 {NSUnderlyingError=0xb178d70 \"JSON serialisation not supported for NSConcreteData\", NSLocalizedDescription=Unsupported value for key uploadedfile in object}" 

数据的打印描述:
注意:试图让非对象的财产E:\ wwwroot的\队伍\上线vikramjit \ test.php的

通知:试图让非对象的财产E:\ wwwroot的\队伍\ vikramjit \ test.php的上线

注意:试图获得非对象的财产E:\ wwwroot文件\队伍\ vikramjit \ test.php的上线

注意:试图让非对象的财产E:\ wwwroot的\队伍\ vikramjit \ test.php的上线

注意:试图让非对象的财产E:\ wwwroot的\队伍\ vikramjit \ test.php的上线

请帮我.....

回答

0

JSON不能包含二进制数据。您应该将文件内容编码为字符串(使用base64或其他算法)并将其保存在NSString中。