通过JSON Web服务上传PDF文件

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; 

}

  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}" 

打印数据说明:
注意 :试图在第7行的E:\ wwwroot \ Team \ vikramjit \ test.php中获取非对象的属性

注意 :试图在第8行的E:\ wwwroot \ Team \ vikramjit \ test.php中获取非对象的属性

注意 :试图在第9行的E:\ wwwroot \ Team \ vikramjit \ test.php中获取非对象的属性

注意 :试图在第10行的E:\ wwwroot \ Team \ vikramjit \ test.php中获取非对象的属性

注意 :试图在第11行的E:\ wwwroot \ Team \ vikramjit \ test.php中获取非对象的属性

请帮我解决…..

JSON不能包含二进制数据。 您应该将文件内容编码为一个string(使用base64或其他algorithm)并将其保存在NSString