排查读取json

develop
PL 4 months ago
parent 436e4d807a
commit 267facc601

@ -312,30 +312,25 @@ public class ChatMessageServiceImpl implements ChatMessageService {
ChatModelDto chatModel = null;
//验证获取模型数据 异常问题
File file = null;
try {
String fileText = FileUtil.getFileText("Json/ChatModel.json");
//转换问题
try {
//String strData01 = JSON.toJSONString(fileText);
String jsonData = JSON.toJSONString(fileText);
//获取聊天字段中的数据
Object str = JSON.parseObject(fileText).get("chatModel");
String strData1 = JSON.toJSONString(str);
Object obj = JSON.parseObject(jsonData).get("chatModel");
String jsonData01 = JSON.toJSONString(obj);
//转换方式
chatModels = JSON.parseObject(strData1, new TypeReference<List<ChatModelDto>>() { });
chatModels = JSON.parseObject(jsonData01, new TypeReference<List<ChatModelDto>>() {});
log.info("获取地址fileText"+fileText+"----文件内容Data:"+ jsonData +"----获取模型集合Object" + obj +"----获取模型集合String"+ jsonData01 +"----获取模型集合机构:"+chatModels);
} catch (Exception e) {
throw new ServiceException(ErrorCode.OPERATION_ERROR.getCode(), "类型转换失败");
throw new ServiceException(ErrorCode.OPERATION_ERROR.getCode(), "读取文件" + Arrays.toString(e.getStackTrace()) + e.getMessage());
}
/*try {
//File file = null;
//chatModels = readResourceFile("Json/ChatModel.json");
//String str = readResourceFile("Json/ChatModel.json");
//file = new File(ClassLoader.getSystemResource("Json/ChatModel.json").getPath()); //相对路径获取文件信息
//File file = new File("src/main/resources/Json/ChatModel.json"); //绝对路径获取文件信息
} catch (Exception e) {
throw new ServiceException(ErrorCode.OPERATION_ERROR.getCode(), "读取文件" + Arrays.toString(e.getStackTrace()) + e.getMessage());
}
/*try {
//chatModel = readerMethod(file);
chatModels = readerMethod(file);
} catch (Exception e) {
throw new ServiceException(ErrorCode.OPERATION_ERROR.getCode(), "读取文件并转换实体类" + Arrays.toString(e.getStackTrace()));
@ -352,8 +347,7 @@ public class ChatMessageServiceImpl implements ChatMessageService {
if (chatModel != null) {
//角色条件
builder.append(String.format(chatModel.getRole(), chatCommentsDto.getPeriod(),
chatCommentsDto.getSubject()));
builder.append(String.format(chatModel.getRole(), chatCommentsDto.getPeriod(), chatCommentsDto.getSubject()));
}
ChatModelDto finalChatModel = chatModel;

Loading…
Cancel
Save