2013-10-07 97 views
-2

我想發送我的字節數據使用一些存在的Web服務。現在我不想更多地探索Web服務,但我只希望將我的以下Byte數據發佈到一些已經存在的Web服務中。例如,以下是我的字節數據。發送字節數據到web服務在cocos2d iphone

Byte *byteData = (Byte*)malloc(len); 
memcpy(byteData, (Byte*)myData, len); 

我該怎麼做!我只想使用Existed Web Service,您的幫助將不勝感激。

EDITED

我有我的NSData JSON格式了。如下面的代碼

const unsigned char *bytes = [myData bytes]; // no need to copy the data 

NSUInteger length = [myData length]; 

NSMutableArray *byteArray = [NSMutableArray array]; 

for (NSUInteger i = 0; i < length; i++) 
{ 

    [byteArray addObject:[NSNumber numberWithUnsignedChar:bytes[i]]]; 
} 

NSDictionary *dictJson = [NSDictionary dictionaryWithObjectsAndKeys: 
          byteArray, @"vedio", 
          nil]; 

NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dictJson options:0 error:NULL]; 
+1

你的web服務有什麼參數? – Robert

+0

Web服務究竟是如何接收數據的?什麼格式(JSON,XML,URL參數...)它預期的是什麼? – LearnCocos2D

+0

@ LearnCocos2D我對這部分稱爲Web服務非常陌生,不知何故,我需要以字節格式將我的數據發送到我的Web服務,我將使用Json&post方法,如鏈接http://www.raywenderlich .com/2965/how-to-write-an-ios-app-that-uses-a-web-service ...仍然我很困惑我該如何做到這一點.. –

回答

0

我只是把我的N​​SData或者說ByteData這樣的:

NSMutableDictionary *dictParam = [NSMutableDictionary dictionary]; 

[dictParam setValue:mydata forKey:@"pattern"]; 

NSString *Web_str_pattern = @"my webservice link"; 

JSONParser *parser = [[JSONParser alloc]initWith_withURL:Web_str_pattern withParam:dictParam withData:nil withType:kPostURL withSelector:@selector(getData:) withObject:self]; 

在這裏,我使用JSONParser Web服務。