json转换实体bean、数组list

json转实体bean

data=[{"xuHao":"201407140001","scaleNo":"01","qrCode":"440100100002B993","beforeWeight":15.85,"fillingWeight":30.50,"steelno":"013267","fillingWorkerID":"","fillingDate":"2014-07-14 09:29:01"},{"xuHao":"201507140002","scaleNo":"01","qrCode":"4401001000013475","beforeWeight":15.85,"fillingWeight":30.50,"steelno":"003212","fillingWorkerID":"","fillingDate":"2015-07-14 09:33:01"}]

String strObject=request.getParameter("data");

FillingDetailRecordsEntity requestBean=(FillingDetailRecordsEntity)jsonToObject(strObject,FillingDetailRecordsEntity.class);

public static <T> T jsonToObject(String jsonString, Class<T> pojoCalss) {
try{
      Object pojo;
      net.sf.json.JSONObject jsonObject = net.sf.json.JSONObject.fromObject(jsonString);
      pojo = net.sf.json.JSONObject.toBean(jsonObject, pojoCalss);
      return (T)pojo;
    }catch(Exception ex){
               ex.printStackTrace();
               return null;
    }
}

json转实体数组list

JSONArray jsonArray = JSONArray.fromObject(strObject);
List<FillingDetailRecordsEntity> list = JSONArray.toList(jsonArray, FillingDetailRecordsEntity.class);

时间: 2024-08-30 04:56:37

json转换实体bean、数组list的相关文章

序列化工具类({对实体Bean进行序列化操作.},{将字节数组反序列化为实体Bean.})

package com.dsj.gdbd.utils.serialize; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.ObjectInputStream; import java.io.ObjectOutputStream; /** * * @作用:序列化工具类 * @功能: * @作者: wyt * @

atitit.XML类库选型及object 对象bean 跟json转换方案

atitit.XML类库选型及object 对象bean 跟json转换方案 1. XML类库可以分成2大类.标准的.这些类库通常接口和实现都是分开的 1 2. 常见的xml方面的方法 2 2.1. xml解析 2 2.2. bean与xml互相转换 2 2.3. json与xml的互相转换 2 3. 大名鼎鼎的 DOM  绿色环保的 SAX 默默无闻的 Digester 2 3.1. 默默无闻的 Digester:XML 的 JavaBean 化 2 4. Digester 解析 XML 3

比Newtonsoft.Json轻量快速简洁的实体JSON转换库YeaJur.Mapper

在使用MVC的时候,我们经常用到Newtonsoft.Json来进行实体和JSON 之间的转换,但是有时候,有些实体Newtonsoft.Json转换会出现异常.YeaJur.Mapper正是为了解决这些问题而来,并比Newtonsoft.Json轻量,转换速度快,使用简洁,测试结果如下 PK项 YeaJur.Mapper Newtonsoft.Json 版本 1.0 9.0.1 大小 6KB 514KB 实例(json格式) [ { "Products": [ { "Id&

hibernate查询部分字段转换成实体bean

//hibernate查询部分字段转换成实体bean /** * 查询线路信息 */ @Override public List<Line> getSimpleLineListByTj(Map<String,Object> paramMap){ Criteria cr=this.getSession().createCriteria(Line.class,"Line"); // cr.setFetchMode("chuTuanInfo", F

转换实体对象 与string转化数组

/// <summary> /// 转换实体对象 /// </summary> /// <typeparam name="T1">转化的实体</typeparam> /// <typeparam name="T2">转换后的实体</typeparam> /// <param name="t1"></param> /// <param name=&

Jackson2 json 转换Bean, Bean 里没有对应的值 jackson Un的解决方式

遇到这个问题时我找到了 SpringMVC @RequestBody问题:Unrecognized field , not marked as ignorable 这篇文章里说: @JsonIgnoreProperties(ignoreUnknown = true),将这个注解写在类上之后,就会忽略类中不存在的字段,可以满足当前的需要.这个注解还可以指定要忽略的字段.使用方法如下: @JsonIgnoreProperties({ "internalId", "secretKe

把实体bean对象转换成DBObject工具类

import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.util.Date; import org.apache.commons.beanutils.BeanUtils; import com.mongodb.BasicDBObject; import com.mongodb.DBObject; public class BeanUtil { /** * 把实体

.net 实体类与json转换(.net自带类库实现)

注意要点. 1.jsonhelp编写时候添加的引用.System.Runtime.Serialization.Json; 2.实体类需声明为public jsonhelp代码: using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Runtime.Serialization.Json; usin

从零开始学android开发-Json转换利器Gson之实例

Gson 是 Google 提供的用来在 Java 对象和 JSON 数据之间进行映射的 Java 类库.可以将一个 JSON 字符串转成一个 Java 对象,或者反过来. jar和源码下载地址: http://code.google.com/p/google-gson/downloads/list 实体类: public class Student { private int id; private String name; private Date birthDay; public int