org.codehaus.jackson.JsonParseException: Unexpected character ('e' (code 101)): was expecting comma

来源:互联网 发布:淘宝开店话费充值 编辑:程序博客网 时间:2022/07/04 04:41

Json解析数据遇到的问题

最近做项目的时候,涉及多次Json解析,但是突然发现调用同一种解析方法,竟然有的成功,有的不能成功,一下就懵逼了。。

先上代码:

public class ProjectParamVo {
@JsonProperty("VERSION")
private String version;

@JsonProperty("BUSINESSID")
private String businessId;

@JsonProperty("PARAMS")
private List<ProjectParamParamVo> params = new LinkedList<ProjectParamParamVo>();

//构造器,getter/setter

}


InputStream f = new FileInputStream(f);

BufferedReader br = new BufferedReader(new InputStreamReader(f));
String line = null;
while ((line = br.readLine()) != null) {
data.append(line);
}
br.close();
businessID = JsonUtil.getParamJsonId(data.toString());


public static String getParamJsonId(String data) throws IOException {
if (data == null || data.isEmpty()) {
return null;
}

ProjectParamVo paramVo = JsonUtil.getObjectMapper().readValue(data, ProjectParamVo.class);
return paramVo.getBusinessId();
}


文件内容:

{
  "BUSINESSID" : "00000001",
  "PARAMS" : [ {
    "desc" : " ",
    "edittype" : "0",
    "selData" : "",
    "tag" : "03000001",
    "value" : "450001"
  }{
    "desc" : "适用于NAC",
    "edittype" : "0",
    "selData" : "",
    "tag" : "04000014",
    "value" : "8134"
  }{
    "desc" : "1是0否,第一位:消费撤销,第二位:预授权撤销,第三位:预授权完成撤销,第四位:预授权完成(请求)",
    "edittype" : "0",
    "selData" : "",
    "tag" : "02000002",
    "value" : "0111"
  } ],
  "VERSION" : "150803093707"
}

代码怎么看都没问题,跟文件内容比较觉得可以准确解析,可现实总是那么骨感:org.codehaus.jackson.JsonParseException: Unexpected character ('e' (code 101)): was expecting comma,经过排除查找了才发现。。原来中文乱码竟然会有影响。。马不停蹄地改了上面文件流的传入编码:

BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(f), "utf-8"));

问题解决。




0 0
原创粉丝点击