package com.beijxing.TestMain;

 import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List; import org.apache.commons.io.FileUtils; import com.beijxing.entity.Student; import net.sf.json.JSONArray;
import net.sf.json.JSONObject; /**
* JSON文本转换为JSONArray 转换为 List<Object>
* @author 作者 : ywp
* @version 创建时间:2016年10月25日 下午10:30:14
*/
public class TestJson5 {
public static void main(String[] args) {
try {
fileToJson();
} catch (IOException e) {
e.printStackTrace();
}
}
public static void fileToJson() throws IOException{
File file = new File(TestJson5.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);
List<Student> lStudents = new ArrayList<Student>();
//lStudents = JSONArray.toList(jsonArray, Student.class);//过时的方法
lStudents = (List<Student>) JSONArray.toCollection(jsonArray, Student.class);
System.out.println("lStudent:"+lStudents);
}
}

JSON文本转换为JSONArray 转换为 List<Object>的更多相关文章

  1. Json:Java对象和Json文本转换工具类

    Json 是一个用于 Java 对象 和 Json 文本 相互转换的工具类. 安装 下载源码 git clone https://github.com/njdi/durian.git 编译源码 cd ...

  2. List<Object>转换为JSONArray二

    package com.beijxing.TestMain; import java.util.ArrayList; import java.util.Collection; import java. ...

  3. 011-JSON、JSONObject、JSONArray使用、JSON数组形式字符串转换为List<Map<String,String>>的8种方法

    一.JSON数据格式 1.1.常用JSON数据格式 1.对象方式:JSONObject的数据是用 { } 来表示的, 例如: { "id" : "123", & ...

  4. 触电JavaScript-如何将json 二维数组转换为 JSON object

    最近因为项目中使用的是 ActiveReports .Net 产品,因为他们最近新出了  ActiveReports JS 版本,所以内心有点痒痒,想试试这个纯前端版本报表控件到底如何,毕竟我们项目有 ...

  5. json文本装换为JSONArray

    package com.beijxing.TestMain; import java.io.File; import java.io.IOException; import org.apache.co ...

  6. JSONObject与JSONArray,转换为字符串

    public class TestArrayToList { public static void main(String[] args) { // TODO Auto-generated metho ...

  7. JSon_零基础_006_将JSon格式的字符串转换为Java对象

    需求: 将JSon格式的字符串转换为Java对象. 应用此技术从一个json对象字符串格式中得到一个java对应的对象. JSONObject是一个“name.values”集合, 通过get(key ...

  8. 用第三方工具类,将JavaBean、List、Map<String,Object>转成JSON文本

    导入第三方jar包: >commons-beanutils-1.7.0.jar >commons-collections-3.1.jar >commons-lang-2.5.jar ...

  9. python 使用eval() 可以将json格式的数据,转换为原始数据

    使用python 自带的函数可以将json 格式的数据(也就是字符串)转换为原始格式的数据, 当使用json.loads()无法将json格式的数据转换为原始数据(存在多层各种格式类型数据的嵌套), ...

随机推荐

  1. 如何自定义Flask中的响应类

    http://codingpy.com/article/customizing-the-flask-response-class/

  2. SSH in Python

    需要安装paramiko,paramiko需要PyCrypto , PyCrypto 需要GCC编译. 安装PyCrypto: 安装Mingw32,确认环境变量. 下载并编译PyCrypto - se ...

  3. android 评分条 RatingBar 使用及自定义

    一.先上效果图片: 第一个是自定义: 第二个是原生的: 二.atingBar 介绍: RatingBar是基于SeekBar和ProgressBar的扩展,用星型来显示等级评定.使用RatingBar ...

  4. messagePaneHost

    Microsoft.Dynamics.Framework.UI.WinForms.Controls.MessageBarType messageBarType; super(); imageList ...

  5. tiny4412学习一:编译uboot,体验裸机

    首先,我们在ubuntu建立一个自己的文件夹,我的是:​ /home/wang/tiny_4412下有 datasheet  shc(原理图PCB文件夹) src tools src下有 codes  ...

  6. Can't use Subversion command line client:svn

    在Intellij IDEA里checkout东西时出先这个错误提示:Can't use Subversion command line client:svn Subversion command l ...

  7. SQLyog-直接导出JSON格式的数据

          前言:以前做过的一个项目,有这样的一个需求使用搜索引擎来查询对应的区域信息,不过区域信息要先导出来,并且数据格式是JSON格式的,在程序中能实现这个需求,不过下面的这种方法更加的简单,通过 ...

  8. jQuery-表单流程导航

    前言:以前做过一个项目,里面牵涉到流程相关的业务,需要用到流程页面导航的效果,完整的工作流相关的项目以前也做过,需要用到第三方插件,当然这里记录的业务需求没这个麻烦,仅仅需要能有一个页面导航的标题栏, ...

  9. C# .NET 基本概念

    1. private. protected. public. internal 修饰符的访问权限.   private : 私有成员, 在类的内部才可以访问.    protected : 保护成员, ...

  10. MFC 响应控件消息

    第一种,消息映射 第二种,重写OnCommand BOOL CmfcdlgDlg::OnCommand(WPARAM wParam, LPARAM lParam){ switch(wParam) { ...