一直困扰着我的小问题。我一直在向我的AWS RDB发出POST请求。请求应返回json输出。我遇到的问题是我将收回字节,但有时它包含不完整的json,因此将其转换为字典不会起作用。有时我也会收到nsdata收到的空值,但我可以打印出数据的长度。有任何想法吗?这是我的iOS代码请求:
var isExecuting = false;
socket_connection.on('request', function (obj) {
// in other languages you could have done something similar to
// while(isExecuting);
// but that may not work here.
var intrvl = setInterval(function(){
if(!isExecuting){
clearInterval(intrvl);
isExecuting=true;
process(obj);
}
},0); // if necessary put some number greater than 0
});
function process(obj){
readfile(function(content){ //async
//read content
//modify content
writefile(content, function(){ //async
//write content
isExecuting = false;
});
});
}
答案 0 :(得分:2)
在本节中:
if(!receivedData){
receivedData = [[NSMutableData alloc]init];
[receivedData appendData:data];
}
如果尚未创建对象,则只附加数据。你想每次追加。 if语句应如下所示:
if(!receivedData){
receivedData = [[NSMutableData alloc]init];
}
[receivedData appendData:data];