---
title: "通过获得对象属性名称给对象赋值"
author: "feicklpp"
date: "2014-11-14T13:38:07Z"
tags: []
categories: ["Web前端"]
slug: "untitled"
draft: false
lastmod: "2014-11-14T13:38:07Z"
id: 2155989
url: "https://feicklpp.iteye.com/blog/2155989"
---

```java

// 要给对象赋值的数据
Map jsonMap = (Map) JSONObject.parse(jsonData);

// 获得对象list
List<DiagnosisRelation> diaList = diagnosisRelationService.getAllList();
Method[] method = diagnosisPra.getClass().getDeclaredMethods();

for (int j = 0; j < diaList.size(); j++) {
	String fieldName = "set" + diaList.get(j).getFieldName();
	for (int n = 0; n < method.length; n++) {
		if (method[n].getName().equalsIgnoreCase(fieldName)) {
			method[n].invoke(diagnosisPra, jsonMap.get(String
					.valueOf(diaList.get(j).getDiagnosisRelationId())));
		}
	}
}
 
```