InputStream解析异常

本文介绍了解析InputStream中遇到的一个特定异常:非法未加引号的字符,并提供了有效的解决方案。通过对比两种不同的读取方式,展示了如何使用BufferedReader来避免此类问题。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

解析InputStream异常,报错如下:

com.fasterxml.jackson.core.JsonParseException: Illegal unquoted character ((CTRL-CHAR, code 0)): has to be escaped using backslash to be included in string value

 at [Source: (String)"{"code":"0","msg":"Stored in"[truncated 552 chars]; line: 1, column: 30]

实际解析后应为"{"code":"0","msg":"Stored in upload"}";

使用的解析方式为

 while ((length = inputStream.read(bufferBytes)) != -1) {

           String s = new String(bufferBytes, Charset.forName("utf-8"));

           sBuffer.append(s);

       }

解析出现异常,调整解析方式,使用BufferedReader

  BufferedReader br = new BufferedReader(new InputStreamReader(inputStream));
        while ((line = br.readLine()) != null) {
            sb.append(line);
        }

解析成功;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值