天天看點

java對象 json對象 互轉jar包

java對象 json對象 互轉jar包 

<dependency>

      <groupId>net.sf.json-lib</groupId>

      <artifactId>json-lib</artifactId>

      <version>2.4</version>

      <classifier>jdk15</classifier>

   </dependency>

//字元串轉json

JSONObject jsonObject = new JSONObject().fromObject("String");

//json轉java對象

Proposal proposal = new JSONObject().toBean(jsonObject, Proposal.class)

//java對象轉JSON

 JSONObject object =JSONObject.fromObject(user);