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

データの説明の印刷:
通知: E:\wwwroot\Team\vikramjit\test.phpで非オブジェクトのプロパティを取得しようとしています7行目

注意: 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 に答える