Java中JSON字符串和对象的互转

  1. 对象转换成json字符串:

JSONObject.toJSONString(switchmes)

  1. JSON字符串转换成对象:

Switchmes switchmes=(Switchmes) JSONObject.parseObject(bd.getBdmes(),Switchmes.class); Switchmes是对象,bd.getBdmes()是json字符串,根据实际情况进行修改。 主要使用了import com.alibaba.fastjson.JSONObject;

posted @ 2020-12-07 09:56  [奋斗]  阅读(799)  评论(0编辑  收藏  举报