我有一個二進制文件,我試圖把內容放入一個數組,以模擬一個XMLHTTPRequest,它將讀取和返回二進制數據。我已經嘗試了類似的其他帖子,這是我想出的代碼。我不知道爲什麼我不能打印出陣列。更好的方式來獲得類似於下面的函數的結果也將高度讚賞。如何將字節的NSData轉換爲NSArray並打印內容?避免Javascript XMLHTTPRequest
NSString *str0=[[NSBundle mainBundle] pathForResource:@"exec" ofType:nil];
NSData* data0 = [NSData dataWithContentsOfFile:str0];
NSArray* array = [NSKeyedUnarchiver unarchiveObjectWithData:data0];
NSUInteger len= [data0 length];
Byte *byteData = (Byte*)malloc(len);
memcpy(byteData, [data0 bytes], len);
NSLog(@"THIS IS THE exec %b",byteData);
我試圖達到同樣的效果,這個JavaScript將返回在客觀C:
function load_binary_resource(url) {
var req = new XMLHttpRequest();
req.open('GET', url, false);
req.overrideMimeType('text\/plain; charset=x-user-defined');
req.send(null);
if (req.status != 200) {
document.write("fail downloading loader");
stop = 1
};
return req.responseText;
}
你是什麼意思的「二進制數據」?期望結果是數組的字符串元素還是'ArrayBuffer'? – guest271314