有些文本可以通过,有些就出现编码错误,我用Linux查了编码都是一样的啊。
而且我做了下面的转换,还是不行。
String content = new ReadFileByLine(text_name).getContent();
JSONObject res = BaiDuNLP.client.sentimentClassify(content, null);
if (!res.isNull("error_msg")){
byte[] bs = content.getBytes();
try {
content = new String(bs, "GBK");
res = BaiDuNLP.client.sentimentClassify(content, null);
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
}
return Float.valueOf(String.valueOf(res.getJSONArray("items")
.getJSONObject(0)
.get("positive_prob")));