首页 > Web开发 > 详细

json文本装换为JSONArray

时间:2016-10-27 23:08:34      阅读:234      评论:0      收藏:0      [点我收藏+]
 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

原文:http://www.cnblogs.com/yangly/p/6005918.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!