1. 程式人生 > >string轉json

string轉json

status data bee pen spa maven class sys return

首先添加maven依賴

1 <dependency>
2             <groupId>org.json</groupId>
3             <artifactId>org.json</artifactId>
4             <version>chargebee-1.0</version>
5 </dependency>

string轉json

1 public static JSONObject strToJson(String str) throws JSONException{
2 str = "{\"code\":\"0\",\"msg\":\"success\",\"data\":{\"taskStatus\":1}}"; 3 JSONObject jsonObj = new JSONObject(str); 4 System.out.print(jsonObj + "\n"); 5 System.out.print(jsonObj.get("code")); 6 return jsonObj; 7 }

string轉json