开发者

conversion NSMutableData

How to convert from NSMutableData to NSMutableArray?

 NSMutableData * webData=[[NSMutableData alloc] initWithData:self.sendRequestCompains];


- (NSMutableData *)sendRequestCompains{

    NSMutableString *sRequest = [[NSMutableString alloc] init];
    [sRequest appendString:@"<?xml version=\"1.0\" encoding=\"utf-8\"?>"];
    [sRequest appendString:@"<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/\">"];
    [sRequest appendString:@"<soap:Body>"];
    [sRequest appendString:@"<getCOMPAINs xmlns=\"http://tempuri.org/PlatformService/method\">"];
    [sRequest appendString:@"<Id_USR>"];    // any attribute
    [sRequest appendString:@"1"];    // attribute value
    [sRequest appendString:@"</Id_USR>"];
    [sRequest appendString:@"</getCOMPAINs>"];
    [sRequest appendString:@"</soap:Body>"];
    [sRequest appendString:@"</soap:Envelope>"];


    NSURL   *ServiceURL = [NSURL URLWithString:@"http://10.29.7.2/server_comp.php"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:ServiceURL];
    [request addValue:@"text/xml; charset:UTF-8" forHTTPHeaderField:@"Content-Type"];
    [request addValue:@"http://10.29.7.2/server_comp.php/getCOMPAINs" forHTTPHeaderField:@"SOAPAction"]; 
    [request setHTTPMethod:@"POST"];
    [request setHTTPBody:[sRequest dataUsingEncoding:NSUTF8StringEncoding]];
    NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];
    if (conn) {
        myMutableData = [[NSMutableData data] retain];
        NSLog(@"Connection success");
开发者_如何学Python        [NSURLConnection connectionWithRequest:request delegate:self];
        NSError *WSerror;
        NSURLResponse *WSresponse;

    myMutableData = [NSURLConnection sendSynchronousRequest:request returningResponse:&WSresponse error:&WSerror];
        NSLog(@"slt%d",[myMutableData length]);
    }

    return myMutableData;
}


Since your data come from your web server through NSURLConnection, I would suggest converting it to an NSString and inspecting its structure:

NSString* dataStr = [[[NSString alloc] initWithData:receivedData encoding:NSUTF8StringEncoding] autorelease];
NSLog(@"DATA: $@", dataStr);

You will possibly need to parse the result in some way (line by line?) and build the array that way.

If you provide the output, it will possible to help you further.

OLD:

If the NSData object was originally an array encoded through NSKeyedArchiver, you can try with (docs):

[NSKeyedUnarchiver unarchiveObjectWithData:webData];

Otherwise, please specify where this NSData object comes from and how it was created.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜