使用的jar包为net.sf.json
//转化为list
String jsonString = "[{'goodsId':'11','name':'苹果'},{'goodsId':'222','name':'橡胶'}]";
JSONArray jsonArray = JSONArray.fromObject(jsonString);
List<Map<String, Object>> mapListJson = (List) jsonArray;
for (int i = 0; i < mapListJson.size(); i++)
{
Map<String, Object> map = mapListJson.get(i);
System.out.println(map.get("name"));
}
//转化为map
String jsonString = "{'goodsId':'11','name':'苹果'}";
JSONObject jsonArray = JSONObject.fromObject(jsonString);
Map<String, Object> mapListJson = (Map<String, Object>)jsonArray;
System.out.println(mapListJson.get("name"));