[英]Remove first byte from NSMutableData
NSMutableData *requestData = (NSMutableData*)[request responseData];
returns 回报
"[{JSON_STRING}]" “[{JSON_STRING}]”
so I want to strip out the "[" / "]" without converting to NSString and then back to NSData. 所以我想删除“[”/“]”而不转换为NSString然后再转回NSData。 The easiest way to do this is to strip out the first and last byte.
最简单的方法是去除第一个和最后一个字节。
[requestData setLength:[requestData length]-1];
removes the last byte. 删除最后一个字节。
How to remove the first byte? 如何删除第一个字节? I tried the solution below, but doesn't work..
我尝试了下面的解决方案,但不起作用..
NSRange range = {0, 1};
[requestData resetBytesInRange:range];
Here's how you strip the first byte off an NSMutableData: 以下是从NSMutableData中删除第一个字节的方法:
NSRange range = NSMakeRange(0, 1);
[requestData replaceBytesInRange:range withBytes:NULL length:0];
You could use 你可以用
NSRange range = NSMakeRange(1, [requestData length] - 2);
NSData *refinedData = [requestData subdataWithRange:range];
This should take care of both the first and last character. 这应该照顾第一个和最后一个字符。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.