如何向json文件添加其他属性

时间:2013-05-30 14:26:24

标签: java json attributes

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

0 个答案:

没有答案