JSON 的几种简单格式和转换


1、JSON对象---JSONObject
{"fbaCode":"PHX4","fromProvince":"310000","fromCity":"310100","fromProvince":"310000"}
2、JSON数组---JSONArray
[{"fbaCode":"PHX4","fromProvince":"310000","fromCity":"310100","fromProvince":"310000"},{"fbaCode2":"PHX4","fromProvince2":"310000","fromCity2":"310100","fromProvince2":"310000"}]
3、JSON字符串
'{"name":"张三","sex":"男"}'
4、混合

=转换=========
1、string ->json
String json
JSONObject jsonObject = new JSONObject(json)
2、字符串数组转相对应的集合实体类 包:com.alibaba.fastjson
List models = JSONArray.parseArray(array, FbaRegionListModel.class);
3、实体类转json字符串
String s = com.alibaba.fastjson.JSON.toJSONString(model)
4、集合转JsonArray 数组
List models = JSONArray.parseArray(array, FbaRegionListModel.class)
JSONArray.toJSON(models)


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM