json文本装换为JSONArray

Posted 北极星的小乌龟

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 }

 

以上是关于json文本装换为JSONArray的主要内容,如果未能解决你的问题,请参考以下文章

DataSet装换为泛型集合

DataSet装换为泛型集合 222

js获取input上传图片装换为base64格式图片

Java中如何将gbk装换为ansi

Java中如何将gbk装换为ansi

如何将PSD批量装换为JPG如何对PSD批量减小体积