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 <\ n> 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 中获取非对象的属性>
请帮帮我.....
答案 0 :(得分:0)
JSON不能包含二进制数据。您应该将文件内容编码为字符串(使用base64或其他算法)并将其保存在NSString
中。