帮我根据这个json,生成一个实体类,我需要这样转换response = JSONUtil.toBean(origina

动态 未结 0 47
邮箱用户_pb5l1
邮箱用户_pb5l1 LV1 2月4日 15:20 发表
摘要:
帮我根据这个json,生成一个实体类,我需要这样转换response = JSONUtil.toBean(originalData, AnthropicApiCommonResponse.class); {"id":"as-j2dybyexkk","object":"chat.completion.chunk","created":1738652789,"model":"deepseek-r1","choices":[{"index":0,"delta":{"content":"提供帮助。"},"finish_reason":"normal","flag":0}]}
id; } public void setId(String id) { this.id = id; } public String getObject() { return object; } public void setObject(String object) { this.object = object; } public long getCreated() { return created; } public void setCreated(long created) { this.created = created; } public String getModel() { return model; } public void setModel(String model) { this.model = model; } public List getChoices() { return choices; } public void setChoices(List choices) { this.choices = choices; } // Inner class for Choice public static class Choice { private int index; private Delta delta; private String finish_reason; private int flag; // Getters and Setters public int getIndex() { return index; } public void setIndex(int index) { this.index = index; } public Delta getDelta() { return delta; } public void setDelta(Delta delta) { this.delta = delta; } public String getFinish_reason() { return finish_reason; } public void setFinish_reason(String finish_reason) { this.finish_reason = finish_reason; } public int getFlag() { return flag; } public void setFlag(int flag) { this.flag = flag; } } // Inner class for Delta public static class Delta { private String content; // Getters and Setters public String getContent() { return content; } public void setContent(String content) { this.content = content; } } } ``` ### 说明: 1. **主类 `AnthropicApiCommonResponse`**: - `id`:对应 JSON 中的 `id` 字段。 - `object`:对应 JSON 中的 `object` 字段。 - `created`:对应 JSON 中的 `created` 字段。 - `model`:对应 JSON 中的 `model` 字段。 - `choices`:对应 JSON 中的 `choices` 字段,类型为 `List`。 2. **内部类 `Choice`**: - `index`:对应 JSON 中 `choices` 数组中的 `index` 字段。 - `delta`:对应 JSON 中 `choices` 数组中的 `delta` 字段,类型为 `Delta`。 - `finish_reason`:对应 JSON 中 `choices` 数组中的 `finish_reason` 字段。 - `flag`:对应 JSON 中 `choices` 数组中的 `flag` 字段。 3. **内部类 `Delta`**: - `content`:对应 JSON 中 `delta` 对象中的 `content` 字段。 ### 使用方式: 你可以使用 `JSONUtil.toBean(originalData, AnthropicApiCommonResponse.class)` 方法将 JSON 数据转换为 `AnthropicApiCommonResponse` 对象。例如: ```java AnthropicApiCommonResponse response = JSONUtil.toBean(originalData, AnthropicApiCommonResponse.class); ``` 这样就可以方便地访问 JSON 数据中的各个字段了。
收藏(0)  分享
相关标签: 智能问答
问题没解决?让AI助手帮你作答 AI助手
0个回复
  • 消灭零回复