List<ConsumerRecord<?,String>>
时间: 2023-10-14 13:57:26 浏览: 149
可以使用以下代码将String转换为List<ConsumerRecord<?, String>>:
引用\[1\]:
```java
import com.fasterxml.jackson.core.type.TypeReference;
import com.fasterxml.jackson.databind.ObjectMapper;
String str = "\[{\"key\":\"key1\",\"value\":\"value1\"},{\"key\":\"key2\",\"value\":\"value2\"}\]";
ObjectMapper mapper = new ObjectMapper();
List<ConsumerRecord<?, String>> records = mapper.readValue(str, new TypeReference<List<ConsumerRecord<?, String>>>() {});
```
引用\[2\]:
```java
import com.alibaba.fastjson.JSONArray;
String str = "\[{\"key\":\"key1\",\"value\":\"value1\"},{\"key\":\"key2\",\"value\":\"value2\"}\]";
List<ConsumerRecord<?, String>> records = JSONArray.parseArray(str, ConsumerRecord.class);
```
请注意,引用\[1\]使用了Jackson库,而引用\[2\]使用了Fastjson库。您可以根据自己的需求选择适合的库来进行转换。
#### 引用[.reference_title]
- *1* *2* *3* [String与List<实体类>互转](https://blog.csdn.net/jads_/article/details/124401081)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v91^insertT0,239^v3^insert_chatgpt"}} ] [.reference_item]
[ .reference_list ]
阅读全文