我在 java 中使用 JSONObject 生成一个 json 文件。我得到的输出是这样的:
{"entities": [
{
"comments": "Yoyo",
"contractor": "true",
"createdBy": "Moc Naaocb",
"dateOfBirth": "191029683619",
"department": "qa",
"email": "Idpxtt.Qxeisa@hp.com",
"employmentDate": "803891270878",
"expertise": "javaMaster",
"firstName": "Idpxtt",
"gender": "male",
"imageUrl": "",
"lastName": "Qxeisa",
"level": "expert",
"location": "israel",
"manager": "Iex",
"percentageOfTime": "12",
"periodOfService": "74",
"role": "ux",
"team": "platformUI"
}]}
我真正需要的是在生成的字段之前添加和附加数据(属性),数据是恒定的......它看起来像:
{"entities":[{"entity_type":"employee","lastUpdateTime":0,"properties":{
"comments": "BlaBlaBla",
"contractor": "false",
"createdBy": "Zhsraz Olgaaoqi",
"dateOfBirth": "101994924814",
"department": "saas",
"email": "Ogz.Pqqoaeo@hp.com",
"employmentDate": "1141914797543",
"expertise": "javaScriptNinja",
"firstName": "Ogz",
"gender": "male",
"imageUrl": "",
"lastName": "Pqqoaeo",
"level": "softwareEngineer",
"location": "usa",
"manager": "Jiso",
"percentageOfTime": "28",
"periodOfService": "3",
"role": "systemArchitect",
"team": "ux"
}]}
任何帮助将不胜感激......谢谢!
json创建代码
JSONObject json = new JSONObject();
List<Employee> list = new ArrayList<Employee>();
for(int i=0; i<2; i++) {
Employee emp = new Employee();
list.add(emp);
}
int print = 1;
json.accumulate("entities",list);
System.out.println(json.toString(print));