0

NSArray を Web サービスに送信できませんでした。
サービス メソッドは呼び出されません。ただし、他のサービス メソッドの呼び出しは機能します。
Web サービス メソッドは次のとおりです。

[WebMethod]
        public int Method(IList items){...

私の配列はオブジェクトアイテムでいっぱいです:

@interface Item : NSObject
{
    double prop1;
    double prop2;
    double prop3;
}
@property double prop1;
@property double prop2;
@property double prop3;

目的 c から、次のようなデータを送信しようとします。

NSString *soapMsg =
    [NSString stringWithFormat:
     @"<?xml version=\"1.0\" encoding=\"utf-8\"?>"
     "<soap:Envelope xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\">"
     "<soap:Body>"
     "<Method xmlns=\"http://www.mysite.com/\">"
     "<items>"
     "%@"
     "</items>"
     "</Method>"
     "</soap:Body>"
     "</soap:Envelope>", myArray
     ];

    NSURL *url = [NSURL URLWithString: @"http://...."];

    NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:url];
    NSString *msgLength = [NSString stringWithFormat:@"%d", [soapMsg length]];

    [req addValue:@"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    [req addValue:@"http://www.mysite.com/Method" forHTTPHeaderField:@"SOAPAction"];
    [req addValue:msgLength forHTTPHeaderField:@"Content-Length"];
    [req setHTTPMethod:@"POST"];
    [req setHTTPBody: [soapMsg dataUsingEncoding:NSUTF8StringEncoding]];

    conn = [[NSURLConnection alloc] initWithRequest:req delegate:self];

    if (conn)
    {
        webData = [NSMutableData data];
    }



更新

次のように配列を作成すると:

NSArray  * myArrDate = [NSArray arrayWithObjects:@"foo",@"bar",@"baz",nil];

そして、作ります:

NSData *jsonData = [NSJSONSerialization dataWithJSONObject:myArrDate
                                                       options:0
                                                         error:nil];

できます。しかし、私はプロパティを持つオブジェクトUserを持つ配列を持っています:UserId, FirstName, LastName, Email, Username, DisplayName, Country, Cityなど. 上記のコードをユーザーの配列で試すと、その行でアプリケーションがクラッシュします。

4

4 に答える 4

6

NSArrayに送信できますwebservice

NSData *jsonData2 = [NSJSONSerialization dataWithJSONObject:yourArray options:NSJSONWritingPrettyPrinted error:nil];
         NSString *jsonString = [[NSString alloc] initWithData:jsonData2 encoding:NSUTF8StringEncoding];
         NSLog(@"FemaleFriendList:\n%@", jsonString);
于 2013-09-20T10:02:35.823 に答える
1

NSArray を Web サービスに送信することはできませんが、送信したい場合は、まずその NSArray を以下のように NSString に変換します。

NSString *stringDelete = [YourNSArray componentsJoinedByString:@","];

次に、その NSString を webservice に渡します。動作しているかどうかを教えてください!!!!!!ハッピー コーディング...!!!

于 2012-11-01T11:59:00.830 に答える
0

NSString(%@、myArray)をパラメーターとして送信しており、WebサービスはIListオブジェクトを予期しています。NSArrayを送信する前にシリアル化してみませんか?たとえば、JSONを使用できます。

于 2012-11-01T11:37:44.620 に答える