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

RE: [json] json as js variable

Expand Messages
  • Mark Ireland
    This is the right general idea but . . ... I am thinking: var myJSObject =
    Message 1 of 19 , Dec 20, 2006
    • 0 Attachment
      This is the right general idea but . . ...

      I am thinking:
      var myJSObject =
      {"RECORDCOUNT":3,"UNIQUEIDS":["js73012","js73016","js73029"],"COLUMNNAMES":["myColumnName1","myColumnName2","myColumnName3",.
      . ...],"js73012":{"CURRENTROW":1,"c1":9,"c2":2006,"c3":007,. . ....}

      all so I can build a table in a form with dynamically named checkboxs.

      But am I reinventing the wheel here? Should I be using stuff from
      prototype.js?


      >From: "Atif Aziz" <atif.aziz@...>
      >Reply-To: json@yahoogroups.com
      >To: <json@yahoogroups.com>
      >Subject: RE: [json] json as js variable
      >Date: Tue, 19 Dec 2006 14:30:48 +0100
      >
      >I think I know what you're looking for here. Suppose the following
      >table:
      >
      >var table = {
      > "columns" : [ "FirstName", "LastName" ],
      > "rows" : [
      > [ "Mickey", "Mouse" ],
      > [ "Donald", "Duck" ],
      > [ "Minnie", "Mouse" ]
      > ]
      >};
      >
      >Suppose further a function we add to the Array object's prototype:
      >
      >Array.prototype.toObject = function(names)
      >{
      > var o = {};
      > for (var i = 0; i < names.length; i++)
      > o[names[i]] = i < this.length ? this[i] : null;
      >
      > return o;
      >}
      >
      >Now you can conveniently convert any row of the table into an object in
      >one swell swoop like this:
      >
      >var o = table.rows[1].toObject(table.columns);
      >
      >This gives you non-repeating column names in the original table
      >definition in JSON, which may be useful to keep the data on the wire
      >small, yet object-like access (dot-syntax) to a row once in script.
      >
      >Hope this help.
      >
      >-----Original Message-----
      >From: json@yahoogroups.com [mailto:json@yahoogroups.com] On Behalf Of
      >Mark Ireland
      >Sent: Sunday, December 17, 2006 11:19 PM
      >To: json@yahoogroups.com
      >Subject: Re: [json] json as js variable
      >
      >
      >Thanks, that got it working.
      >
      >Now I am wondering if there is some alternative to repeating the column
      >names in every object.
      >
      > >From: "Matthew Morley" <WickedLogic@...
      ><mailto:WickedLogic%40gmail.com> >
      > >Reply-To: json@yahoogroups.com <mailto:json%40yahoogroups.com>
      > >To: json@yahoogroups.com <mailto:json%40yahoogroups.com>
      > >Subject: Re: [json] json as js variable
      > >Date: Mon, 11 Dec 2006 06:41:03 -0500
      > >
      > >*Identifiers* are names for constants, variables, functions, loop
      >labels,
      > >objects and classes. The first character must be an ASCII letter,
      > >underscore
      > >or dollar sign. Following characters can also include digits.
      > >
      > >Even 'u80020' will do. You can only use numeric indexes if you are
      > >producing
      > >an array.
      > >
      > >--
      > >Matthew P. C. Morley
      > >
      > >
      > >[Non-text portions of this message have been removed]
      > >
      >
      >__________________________________________________________
      >Join the millions of Australians using Live Search. Try live.com.au
      >http://ninemsn.com.au/share/redir/adTrack.asp?mode=click&clientID=740&re
      >ferral=million&URL=http://live.com.au
      ><http://ninemsn.com.au/share/redir/adTrack.asp?mode=click&clientID=740&r
      >eferral=million&URL=http://live.com.au>
      >
      >
      >
      >

      _________________________________________________________________
      Join the millions of Australians using Live Search. Try live.com.au
      http://ninemsn.com.au/share/redir/adTrack.asp?mode=click&clientID=740&referral=million&URL=http://live.com.au
    Your message has been successfully submitted and would be delivered to recipients shortly.