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));