Loading ...
Sorry, an error occurred while loading the content.

550How to acess Java Objects, using JSON

Expand Messages
  • krish777
    Oct 22, 2006
      Hi,

      I am new to JSON an I am learning JSON. I have a question for the group.

      I have a button and onclick of the button, I am calling a servlet and
      I want to pass Person Object to the client. In doGet() method I am
      doing the following things

      JSONObject obj = new JSONObject();
      Vector v = new Vector();
      v.add(new Employee("Jim", "1"));
      v.add( new Employee("Tom", "2"));
      obj.put("emp", v);
      res.getWriter().print(obj);

      In Call back javascript, how to access the properties of the employee
      object?

      var jsonExpression = "(" + object.responseText + ")";
      var customer = eval(jsonExpression);
      alert(customer.emp[0].firstName);

      I want to display back employee name and employee id.

      Please help.
    • Show all 4 messages in this topic