import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.io.IOUtils;
InputStream in = ProductListServlet.class.getResourceAsStream("/product.json");
String result = IOUtils.toString(in,"UTF-8");
//一个JsonObject文本数据
System.out.println(result);
//将JsonObject数据转换为Json
JSONObject object = JSON.parseObject(result);
System.out.println(object);
System.out.println(object.get("id"));
引入了apache的io包 转换InputStream到String
阿里巴巴json的api学习:地址