3

这是我从服务器读取数据的代码。我的问题是我得到了 435 个字节,但我无法将该数据转换为可读格式NSString。我的服务器发送这个对象:

public class SymbolData
{
public string Symbol { get; set; }
public double AskPrice { get; set; }
public double BidPrice { get; set; }
public double Open { get; set; }
public double High { get; set; }
public double Low { get; set; }
public double Close { get; set; }
public double PerChange { get; set; }
public double NetChange { get; set; }
public int Volume { get; set; }
}  

我从服务器获取这个对象。在这里,我以字节为单位检索它们。现在我只想将该数据字节转换NSMuatableArray为在我的表格视图上打印。我的代码:

case NSStreamEventHasBytesAvailable:
if (stream == inputStream) {

            uint8_t buffer[1024];
            int len;

            while ([inputStream hasBytesAvailable]) {

                len = [inputStream read:buffer maxLength:sizeof(buffer)];
                if (len > 0) {

                    NSData *data=[[NSData alloc] initWithBytes:buffer length:len];
                    NSLog(@"%@",data);

//NSString *array=[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];

//NSLog(@"%@",array);
                    unsigned char* bytes = (unsigned char*) [data bytes];

                    for(int i=0;i< [data length];i++)
                    {
                        NSString* op = [NSString stringWithFormat:@"%d:%X",i,bytes[i],nil];
                         NSLog(@"server said: %@  ", op);
                    }


                    NSString *output = [[NSString alloc] initWithBytes:buffer length:len encoding:NSASCIIStringEncoding];

                    if (nil != output) {
                        NSLog(@"server said: %@ %@ ", output,data);
                    }
                }
            }
        }

这是 Nslog 数据:<0f4f3483 8727ea3f 4927b151 a493e83f eab8e3db 74dce13f 97be345d 4b5fca3f c5c4635d 62e2e13f 59fc3979 2cfeec3f 4999386c a44cdc3f 2d907e6b 1648ef3f 94c32900 45555247 42500000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 9f0f2460 c0c73200 00000000 64272360 cc4d9677 90656c75 ffffffff c0c73200 08000000 01000000 60f41a04 0dbf2460 f8d0bbea 7be8dd3f 7c7d683d be3ee43f f718bc8c 7b0cde3f 91dbfe76 c86def3f 0c313e40 86189f3f 1331f74a 8998eb3f c4b33f1f e2d9ef3f f0562bcd 77abe53f bd003000 47425055 53440000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 9f0f2460 c0c73200 00000000 64272360 cc4d9677 90656c75 ffffffff c0c73200 08000000 01000000 60f41a04 0dbf2460 7b46367e 3d23eb3f 537b7fa1 a9bdef3f 80682100 40b4a03f d9cb2cbb​​ ec65e63f a4aea1d7 51d7e03f f6c63b197be3ed3f f8012c40 fc00e63f 06ffe214 837fe13f 5b600c00 45555243 48460000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 9f0f2460 c0c73200 00000000 64272360 cc4d9677 90656c75 ffffffff c0c73200 08000000 01000000 60f41a04 0dbf2460 a006ba06 5003dd3f ba092625 dd04d33f 4d443f90 26a2ef3f f521694a fa90e43f 65d4709d 326ae83f 5d3f3e78 ae1f9f3f c1c430ba 6062d83f 12ec2b36 09f6d53f 97189200 55534443 48460000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 9f0f2460 c0c73200 00000000 64272360 cc4d9677 90656c75 ffffffff c0c73200 08000000 01000000 60f41a04 0dbf2460 7ed2ad2f 3fe9e63f 07e83c84 0374be3f 7500a3a6 3a80d13f e50dba47 f206ed3f 71dd3241 b86ee93f 1228abf5 0894d53f d185baa5 e842dd3f 539625b5 29cbc23f 1bc52100 47425041 55440000 00000000 00000000 0000000000000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 9f0f2460 c0c73200 00000000 64272360 cc4d9677 90656c75 ffffffff c0c73200 08000000 01000000 60f41a04 0dbf2460 9fff2d6a cfffe63f 4daba751 a6d5e33f bd75be5a de3adf3f d9e5316a ecf2c83f 4a347808 251aec3f bcd3b4e1 dd69ea3f c110af51 6088e73f 10edb620 8876eb3f b2b86700 47425041 55440000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 00000000 9f0f2460 c0c73200 00000000 64272360 cc4d9677 90656c75 ffffffff c0c73200 08000000 01000000 60f41a04 0dbf2460 82e937e4 c0f4cb3f 9e4d3921 c>

4

0 回答 0