在实际过程中,经常要将实体类进行封装,尤其是处理数据库的过程中:因此,对于遍历实体类能够与数据库中的一行数据对应起来. 我是使用的环境是Spring boot,访问的数据库时MongoDB 实体类遍历: //java中遍历实体类,获取属性名和属性值 public static void testReflect(Object model) throws Exception{ for (Field field : model.getClass().getDeclaredFields()) { fie
1.定义实体类 [DataContract] public class CustomerWordOrderViewModel { [DataMember] public string Name; [DataMember] public int Age; } 2.通过DataContractJsonSerializer类进行序列化/反序列化 string strJson = "[{\"Age\":28,\"Name\":\"张三\"},{