json文本装换为JSONArray

时间:2022-10-04 18:24:16
 package com.beijxing.TestMain;

 import java.io.File;
import java.io.IOException; import org.apache.commons.io.FileUtils; import net.sf.json.JSONArray;
import net.sf.json.JSONObject; /**
* JSON文本转换为JSONArray
* @author 作者 : ywp
* @version 创建时间:2016年10月25日 下午10:30:14
*/
public class TestJson4 {
public static void main(String[] args) {
try {
fileToJson();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void fileToJson() throws IOException{
File file = new File(TestJson4.class.getResource("/jsonText2.json").getFile());//获取项目根路径下的文件
String content = FileUtils.readFileToString(file);
//JSONObject jsonObject = JSONObject.fromObject(content);
JSONArray jsonArray = JSONArray.fromObject(content);
System.out.println("jsonarray:"+jsonArray);
}
}