在使用Gson解析JSON数据时,报错:Caused by: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 3939
原因:传入的参数有问题;
while((len=inputStream.read(data))!=-1){ outPutStream.write(data,0,len); }
错写成:
while((len=inputStream.read())!=-1){ outPutStream.write(data,0,len); }
导致:
String jsonString=HttpUtils.getJsonContent(path); System.out.println("jsonString-->:"+jsonString.toString()); Person person=GsonTools.getPerson(jsonString.trim(), Person.class);
上段GsonTools.getPerson中的jsonString参数有问题,从而引起报错,其实质是:传入的JSON字符串格式不对导致