FIleText转换为JSONObject对象

 1 package com.beijxing.TestMain;
 2 
 3 import java.io.File;
 4 import java.io.IOException;
 5 
 6 import org.apache.commons.io.FileUtils;
 7 
 8 import net.sf.json.JSONObject;
 9 
10 /** 
11 *
12 * @author 作者 : ywp
13 * @version 创建时间:2016年10月25日 下午10:30:14 
14 */
15 public class TestJson2 {
16     public static void main(String[] args) {
17         try {
18             fileToJson();
19         } catch (IOException e) {
20             e.printStackTrace();
21         }
22     }
23     public static void fileToJson() throws IOException{
24         File file = new File(TestJson2.class.getResource("/jsonText.json").getFile());//获取项目根路径下的文件
25         String content = FileUtils.readFileToString(file);
26         JSONObject jsonObject = JSONObject.fromObject(content);
27         System.out.println("jsonObject="+jsonObject);
28     }
29 }
原文地址:https://www.cnblogs.com/yangly/p/5998755.html