json文本装换为JSONArray

 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.JSONArray;
 9 import net.sf.json.JSONObject;
10 
11 /** 
12 * JSON文本转换为JSONArray
13 * @author 作者 : ywp
14 * @version 创建时间:2016年10月25日 下午10:30:14 
15 */
16 public class TestJson4 {
17     public static void main(String[] args) {
18         try {
19             fileToJson();
20         } catch (IOException e) {
21             e.printStackTrace();
22         }
23     }
24     public static void fileToJson() throws IOException{
25         File file = new File(TestJson4.class.getResource("/jsonText2.json").getFile());//获取项目根路径下的文件
26         String content = FileUtils.readFileToString(file);
27         //JSONObject jsonObject = JSONObject.fromObject(content);
28         JSONArray jsonArray = JSONArray.fromObject(content);
29         System.out.println("jsonarray:"+jsonArray);
30     }
31 }
原文地址:https://www.cnblogs.com/yangly/p/6005918.html