JSON as datasource

Discussion in 'JavaScript' started by holtmann, Aug 16, 2007.

  1. #1
    Hi,

    I got a question regarding JSON as datasource- I understand that eval on a JSON String creates the appropriate objects in JS.
    But I would like to use JSON to supply data to already defined prototpye objects. I try to give an example. I e.g. got:

    address.prototype =
    {
    firstname: null;
    lastname: null;
    email: null;
    //imagine a lot more properties here

    getfirstname: function () { return this.firstname; },
    checkadress: function() {//some code here;}
    }

    Imagine address has a lot of properties and methods. Now I want to use JSON to create a new address-object and initialize the properties with the data supplied in the JSON Object. How can I do this without having to write a lot of code? What would the JSON Object have to look like?


    Best,

    Hendrik
     
    holtmann, Aug 16, 2007 IP