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;

}

  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中非对象的属性注意:尝试在E :\wwwroot\Team\vikramjit中获取非对象的属性第8行的\test.php注意:尝试在E:\wwwroot\Team\vikramjit\test.php中获取非对象的属性 在第9注意:尝试在E:\wwwroot\Team中获取非对象的属性第10行的\vikramjit\test.php注意:第11行的E:\wwwroot\Team\vikramjit\test.php试图获取非对象的属性








请帮帮我......

4

1 回答 1

0

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

于 2012-10-26T08:12:14.280 回答