JSON转为实体类 、 List<Map<String,Object>> 转为 实体类 、实体类转为 JSON String
json
适用于现代 C++ 的 JSON。
项目地址:https://gitcode.com/gh_mirrors/js/json

·
1.JSON转为实体类
Entity entity = JSONObject.parseObject(new JSONObject.toJSONString(), Entity.class);
2.List<Map<String,String>> 转为 临时JSONArray,然后由 JSONArray 转为 List<实体类>,其次再由 entityList 转为 真正JSONArray
//1.新建一个 List<Map<String,String>>
List<Map<String,String>> tempEntityList=new ArrayList<Map<String,String>>();
//2.把 tempEntityList转为 JSONArray
JSONArray array= JSONArray.parseArray(JSON.toJSONString(tempEntityList));
//3.把 array 转为 List<Entity> entityList
List<Entity> entityList = JSONObject.parseArray(array.toJSONString(), Entity.class);
//4.把 entityList 转为JSONArray
JSONArray.parseArray(JSON.toJSONString(entityList))
3.实体类转为 JSON String
//1.创建实体类
Entity entity = new Entity;
//2.创建Jackson对象 ObjectMapper
ObjectMapper mapper = new ObjectMapper();
//3.转换为JSOn
String json = mapper.writeValueAsString(entity);
4.List<Map<String,Object>> 转为 实体类
//1.新建 临时 tempEntityList
List<Map<String,Object>> tempEntityList=new ArrayList<Map<String,Object>>();
//2.获取 临时 tempEntityList 第一条数据 转为所需要的实体类
JSONObject.toJavaObject(JSONObject.parseObject(JSONObject.toJSONString(tempEntityList.get(0))),Entity.class)
最后,创作不易,请大家多多支持




适用于现代 C++ 的 JSON。
最近提交(Master分支:17 天前 )
230bfd15
Bumps [actions/dependency-review-action](https://github.com/actions/dependency-review-action) from 4.6.0 to 4.7.0.
- [Release notes](https://github.com/actions/dependency-review-action/releases)
- [Commits](https://github.com/actions/dependency-review-action/compare/ce3cf9537a52e8119d91fd484ab5b8a807627bf8...38ecb5b593bf0eb19e335c03f97670f792489a8b)
---
updated-dependencies:
- dependency-name: actions/dependency-review-action
dependency-version: 4.7.0
dependency-type: direct:production
update-type: version-update:semver-minor
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 5 天前
e9391dc5
Bumps [lukka/get-cmake](https://github.com/lukka/get-cmake) from 4.0.1 to 4.02.
- [Release notes](https://github.com/lukka/get-cmake/releases)
- [Commits](https://github.com/lukka/get-cmake/compare/57c20a23a6cac5b90f31864439996e5b206df9dc...ea004816823209b8d1211e47b216185caee12cc5)
---
updated-dependencies:
- dependency-name: lukka/get-cmake
dependency-version: '4.02'
dependency-type: direct:production
...
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> 7 天前
更多推荐
所有评论(0)