美文网首页iOS
iOS 字节数组Byte byte[]={1,2,3}

iOS 字节数组Byte byte[]={1,2,3}

作者: 齐云霄霄 | 来源:发表于2022-01-29 09:57 被阅读0次

    今天同事突然发来一串神奇的数据,说让帮忙解析下payload里面内容,说是隔壁安卓大佬已经成功解析。

    {
      "payload" :[123,34,114,101,97,100,95,109,115,103,73,100,34,58,34,66,118,118,108,111,119,72,81,110,114,68,75,80,120,79,45,54,34,125],
      "msgId" : "Gk7V586t09OVg99-2",
      "timestamp" : 1643345502380,
      "version" : 0
    }
    

    我心想这是啥,我和它互不相识啊,一定是后台数据编码格式搞错了让他们改!!后来孤陋寡闻的我经过多方打听原来是字节数组Byte

    好了话不多说新建demo测试一下,上代码

    Byte byteData[] = {123,34,114,101,97,100,95,109,115,103,73,100,34,58,34,66,118,118,108,111,119,72,81,110,114,68,75,80,120,79,45,54,34,125};
    NSData *temphead = [[NSData alloc]initWithBytes:byteData length:sizeof(byteData)];
    NSString *str = [[NSString alloc]initWithData:temphead encoding:NSUTF8StringEncoding];
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:temphead options:NSJSONReadingAllowFragments error:nil];
    
    NSLog(@"%@",str);
    

    这是对应断点调试结果


    WX20220129-095525.png

    相关文章

      网友评论

        本文标题:iOS 字节数组Byte byte[]={1,2,3}

        本文链接:https://www.haomeiwen.com/subject/pdixkrtx.html