Map<String, Object> stringObjectMap = JSONUtils.jsonStrToMap(params); 怎么转成<String.String>
时间: 2023-11-11 19:54:50 浏览: 134
map.toString()后转换成Map类型
4星 · 用户满意度95%
要将Map<String, Object>转换为Map<String, String>,你可以遍历原始的Map,然后将每个键值对中的值转换为String类型,并将其放入新的Map中。以下是示例代码:
```java
Map<String, Object> stringObjectMap = JSONUtils.jsonStrToMap(params);
Map<String, String> stringStringMap = new HashMap<>();
for (Map.Entry<String, Object> entry : stringObjectMap.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
String stringValue = String.valueOf(value);
stringStringMap.put(key, stringValue);
}
```
这样,你就可以将Map<String, Object>转换为Map<String, String>了。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [map与json互转](https://blog.csdn.net/weixin_42005527/article/details/95659548)[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^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
阅读全文