json字符串轉(zhuǎn)javamap?
我們需要先把json字符串轉(zhuǎn)化為net.sf.json.JSONObject對象,java中這樣就可以完成json字符串到Map的轉(zhuǎn)換了。
1.將數(shù)組轉(zhuǎn)換為JSON:String[] arr = {"asd","dfgd","asd","234"};JSONArray jsonarray = JSONArray.fromObject(arr);System.out.println(jsonarray);
2.對象轉(zhuǎn)換成JSON:UserInfo user = new UserInfo(1001,"張三");JSONArray jsonArray = JSONArray.fromObject(user);System.out.println( jsonArray );
3.把Map轉(zhuǎn)換成json, 要使用jsonObject對象:Map