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

Re: [json] json as js variable

Expand Messages
  • Martin Cooper
    ... It s just a JavaScript object, so you can access pieces of it in the same way as you would with any other JavaScript object. There s no magic. say
    Message 1 of 19 , Dec 9, 2006
    • 0 Attachment
      On 12/9/06, Mark Ireland <markincuba@...> wrote:
      >
      >
      > Is there any javascript code for finding a json variable by its key?


      It's just a JavaScript object, so you can access pieces of it in the same
      way as you would with any other JavaScript object. There's no magic.

      say jsonStuff.DATA.UNIQUEID[uniqueid]


      Without knowing what your data structure looks like, it's kinda hard to tell
      if this is valid or not, but if all the right objects exist in all the right
      places, sure, that would be valid code.

      --
      Martin Cooper


      >From: Jesse Skinner <jesse@...>
      > >Reply-To: json@yahoogroups.com
      > >To: json@yahoogroups.com
      > >Subject: Re: [json] json as js variable
      > >Date: Thu, 07 Dec 2006 20:32:47 -0500
      > >
      > >Hi Mark,
      > >
      > >Perhaps instead of:
      > >
      > > for (var j in jsonStations.RECORDCOUNT) {
      > >
      > >you should try:
      > >
      > > for (var j=0;j < jsonStations.RECORDCOUNT;j++) {
      > >
      > >? I'm not sure without seeing your JSON, but this is my best guess.
      > >
      > >All the best,
      > >
      > >Jesse
      > >http://www.thefutureoftheweb.com
      > >
      > >Mark Ireland wrote:
      > > > I have initialised a json string as a js variable and this simple test
      > >is
      > > > working:
      > > >
      > > > a href="##"
      > > >
      > >onclick="alert(typeof(jsonStations.DATA.MYVARIABLE
      > [0].toString()))">myJSONVariable</a
      > > > a href="##"
      > > >
      > >onclick="alert(typeof(jsonStations.RECORDCOUNT))">
      > myJSONObject.recordcount</a
      > > >
      > > > But this does not:
      > > >
      > > > function findNumChecked() {
      > > > var num = 0;
      > > > var chk = null;
      > > > for (var j in jsonStations.RECORDCOUNT) {
      > > > id = jsonStations.DATA.MYVARIABLE[j].toString();
      > > > chk = document.getElementById(id);
      > > > if (chk && chk.checked) num++;
      > > > }
      > > > return num;
      > > > }
      > > >
      > > > What am I missing?
      > >
      >
      > _________________________________________________________________
      > Advertisement: Meet Sexy Singles Today @ Lavalife - Click here
      >
      > http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Flavalife9%2Eninemsn%2Ecom%2Eau%2Fclickthru%2Fclickthru%2Eact%3Fid%3Dninemsn%26context%3Dan99%26locale%3Den%5FAU%26a%3D23769&_t=754951090&_r=endtext_lavalife_dec_meet&_m=EXT
      >
      >
      >
      >
      > Yahoo! Groups Links
      >
      >
      >
      >


      [Non-text portions of this message have been removed]
    • Mark Ireland
      Thanks. I was hoping there was a js function library where you just pass the unique id and the row is returned. Is there one? ...
      Message 2 of 19 , Dec 10, 2006
      • 0 Attachment
        Thanks. I was hoping there was a js function library where you just pass the
        unique id and the row is returned.
        Is there one?

        >From: "Martin Cooper" <mfncooper@...>
        >Reply-To: json@yahoogroups.com
        >To: json@yahoogroups.com
        >Subject: Re: [json] json as js variable
        >Date: Sat, 9 Dec 2006 15:51:40 -0800
        >
        >On 12/9/06, Mark Ireland <markincuba@...> wrote:
        > >
        > >
        > > Is there any javascript code for finding a json variable by its key?
        >
        >
        >It's just a JavaScript object, so you can access pieces of it in the same
        >way as you would with any other JavaScript object. There's no magic.
        >
        >say jsonStuff.DATA.UNIQUEID[uniqueid]
        >
        >
        >Without knowing what your data structure looks like, it's kinda hard to
        >tell
        >if this is valid or not, but if all the right objects exist in all the
        >right
        >places, sure, that would be valid code.
        >
        >--
        >Martin Cooper
        >
        >
        > >From: Jesse Skinner <jesse@...>
        > > >Reply-To: json@yahoogroups.com
        > > >To: json@yahoogroups.com
        > > >Subject: Re: [json] json as js variable
        > > >Date: Thu, 07 Dec 2006 20:32:47 -0500
        > > >
        > > >Hi Mark,
        > > >
        > > >Perhaps instead of:
        > > >
        > > > for (var j in jsonStations.RECORDCOUNT) {
        > > >
        > > >you should try:
        > > >
        > > > for (var j=0;j < jsonStations.RECORDCOUNT;j++) {
        > > >
        > > >? I'm not sure without seeing your JSON, but this is my best guess.
        > > >
        > > >All the best,
        > > >
        > > >Jesse
        > > >http://www.thefutureoftheweb.com
        > > >
        > > >Mark Ireland wrote:
        > > > > I have initialised a json string as a js variable and this simple
        >test
        > > >is
        > > > > working:
        > > > >
        > > > > a href="##"
        > > > >
        > > >onclick="alert(typeof(jsonStations.DATA.MYVARIABLE
        > > [0].toString()))">myJSONVariable</a
        > > > > a href="##"
        > > > >
        > > >onclick="alert(typeof(jsonStations.RECORDCOUNT))">
        > > myJSONObject.recordcount</a
        > > > >
        > > > > But this does not:
        > > > >
        > > > > function findNumChecked() {
        > > > > var num = 0;
        > > > > var chk = null;
        > > > > for (var j in jsonStations.RECORDCOUNT) {
        > > > > id = jsonStations.DATA.MYVARIABLE[j].toString();
        > > > > chk = document.getElementById(id);
        > > > > if (chk && chk.checked) num++;
        > > > > }
        > > > > return num;
        > > > > }
        > > > >
        > > > > What am I missing?
        > > >
        > >
        > > _________________________________________________________________
        > > Advertisement: Meet Sexy Singles Today @ Lavalife - Click here
        > >
        > >
        >http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Flavalife9%2Eninemsn%2Ecom%2Eau%2Fclickthru%2Fclickthru%2Eact%3Fid%3Dninemsn%26context%3Dan99%26locale%3Den%5FAU%26a%3D23769&_t=754951090&_r=endtext_lavalife_dec_meet&_m=EXT
        > >
        > >
        > >
        > >
        > > Yahoo! Groups Links
        > >
        > >
        > >
        > >
        >
        >
        >[Non-text portions of this message have been removed]
        >

        _________________________________________________________________
        Advertisement: Meet Sexy Singles Today @ Lavalife - Click here
        http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Flavalife9%2Eninemsn%2Ecom%2Eau%2Fclickthru%2Fclickthru%2Eact%3Fid%3Dninemsn%26context%3Dan99%26locale%3Den%5FAU%26a%3D23769&_t=754951090&_r=endtext_lavalife_dec_meet&_m=EXT
      • Martin Cooper
        ... What do you mean? There is no concept of row in JSON, or even unique IDs, for that matter, beyond the property names in an object. Any structure you are
        Message 3 of 19 , Dec 10, 2006
        • 0 Attachment
          On 12/10/06, Mark Ireland <markincuba@...> wrote:
          >
          >
          > Thanks. I was hoping there was a js function library where you just pass
          > the
          > unique id and the row is returned.
          > Is there one?


          What do you mean? There is no concept of "row" in JSON, or even unique IDs,
          for that matter, beyond the property names in an object. Any structure you
          are imposing on your JSON objects is your own, so there isn't going to be a
          library out there to manipulate that unless you write it. ;-)

          --
          Martin Cooper


          >From: "Martin Cooper" <mfncooper@...>
          > >Reply-To: json@yahoogroups.com
          > >To: json@yahoogroups.com
          > >Subject: Re: [json] json as js variable
          > >Date: Sat, 9 Dec 2006 15:51:40 -0800
          > >
          > >On 12/9/06, Mark Ireland <markincuba@...> wrote:
          > > >
          > > >
          > > > Is there any javascript code for finding a json variable by its key?
          > >
          > >
          > >It's just a JavaScript object, so you can access pieces of it in the same
          > >way as you would with any other JavaScript object. There's no magic.
          > >
          > >say jsonStuff.DATA.UNIQUEID[uniqueid]
          > >
          > >
          > >Without knowing what your data structure looks like, it's kinda hard to
          > >tell
          > >if this is valid or not, but if all the right objects exist in all the
          > >right
          > >places, sure, that would be valid code.
          > >
          > >--
          > >Martin Cooper
          > >
          > >
          > > >From: Jesse Skinner <jesse@...>
          > > > >Reply-To: json@yahoogroups.com
          > > > >To: json@yahoogroups.com
          > > > >Subject: Re: [json] json as js variable
          > > > >Date: Thu, 07 Dec 2006 20:32:47 -0500
          > > > >
          > > > >Hi Mark,
          > > > >
          > > > >Perhaps instead of:
          > > > >
          > > > > for (var j in jsonStations.RECORDCOUNT) {
          > > > >
          > > > >you should try:
          > > > >
          > > > > for (var j=0;j < jsonStations.RECORDCOUNT;j++) {
          > > > >
          > > > >? I'm not sure without seeing your JSON, but this is my best guess.
          > > > >
          > > > >All the best,
          > > > >
          > > > >Jesse
          > > > >http://www.thefutureoftheweb.com
          > > > >
          > > > >Mark Ireland wrote:
          > > > > > I have initialised a json string as a js variable and this simple
          > >test
          > > > >is
          > > > > > working:
          > > > > >
          > > > > > a href="##"
          > > > > >
          > > > >onclick="alert(typeof(jsonStations.DATA.MYVARIABLE
          > > > [0].toString()))">myJSONVariable</a
          > > > > > a href="##"
          > > > > >
          > > > >onclick="alert(typeof(jsonStations.RECORDCOUNT))">
          > > > myJSONObject.recordcount</a
          > > > > >
          > > > > > But this does not:
          > > > > >
          > > > > > function findNumChecked() {
          > > > > > var num = 0;
          > > > > > var chk = null;
          > > > > > for (var j in jsonStations.RECORDCOUNT) {
          > > > > > id = jsonStations.DATA.MYVARIABLE[j].toString();
          > > > > > chk = document.getElementById(id);
          > > > > > if (chk && chk.checked) num++;
          > > > > > }
          > > > > > return num;
          > > > > > }
          > > > > >
          > > > > > What am I missing?
          > > > >
          > > >
          > > > _________________________________________________________________
          > > > Advertisement: Meet Sexy Singles Today @ Lavalife - Click here
          > > >
          > > >
          > >
          > http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Flavalife9%2Eninemsn%2Ecom%2Eau%2Fclickthru%2Fclickthru%2Eact%3Fid%3Dninemsn%26context%3Dan99%26locale%3Den%5FAU%26a%3D23769&_t=754951090&_r=endtext_lavalife_dec_meet&_m=EXT
          > > >
          > > >
          > > >
          > > >
          > > > Yahoo! Groups Links
          > > >
          > > >
          > > >
          > > >
          > >
          > >
          > >[Non-text portions of this message have been removed]
          > >
          >
          > _________________________________________________________________
          > Advertisement: Meet Sexy Singles Today @ Lavalife - Click here
          >
          > http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Flavalife9%2Eninemsn%2Ecom%2Eau%2Fclickthru%2Fclickthru%2Eact%3Fid%3Dninemsn%26context%3Dan99%26locale%3Den%5FAU%26a%3D23769&_t=754951090&_r=endtext_lavalife_dec_meet&_m=EXT
          >
          >
          >
          >
          > Yahoo! Groups Links
          >
          >
          >
          >


          [Non-text portions of this message have been removed]
        • Mark Ireland
          Here is one I prepared earlier:
          Message 4 of 19 , Dec 10, 2006
          • 0 Attachment
            Here is one I prepared earlier:

            {"RECORDCOUNT":30,"COLUMNLIST":"EM,EY,ISSILO,ISWEATHER,LATITUDE,LONGITUDE,PERCENTCOMPLETE,PERCENTQUALITY,SM,UNIQUEID,STATIONNAME,SY,X,Y","DATA":{"EM":[12,5,12,4,10,10,10,10,10,10,10,10,10,10,10,12,10,10,9,12,11,11,12,12,12,10,10,9,3,10],"EY":[2005,2005,2005,2006,2006,2006,2006,2006,2006,2006,2006,2006,2006,2006,2006,2006,2006,.
            . . . . . .
            .....,"X":[291,28,152,171,109,96,268,126,250,123,174,188,199,251,91,238,147,274,97,274,126,167,100,145,207,146,120,160,241,232],"Y":[136,188,197,226,212,211,128,113,126,179,197,175,176,148,51,147,252,153,66,180,224,158,83,73,122,131,151,250,178,134]}};

            I could just loop through this testing for my uniqueID but surely someone
            has written something quicker and more reusable than that? Is this not a
            standard structure?

            >From: "Martin Cooper" <mfncooper@...>
            >Reply-To: json@yahoogroups.com
            >To: json@yahoogroups.com
            >Subject: Re: [json] json as js variable
            >Date: Sun, 10 Dec 2006 14:13:22 -0800
            >
            >On 12/10/06, Mark Ireland <markincuba@...> wrote:
            > >
            > >
            > > Thanks. I was hoping there was a js function library where you just pass
            > > the
            > > unique id and the row is returned.
            > > Is there one?
            >
            >
            >What do you mean? There is no concept of "row" in JSON, or even unique IDs,
            >for that matter, beyond the property names in an object. Any structure you
            >are imposing on your JSON objects is your own, so there isn't going to be a
            >library out there to manipulate that unless you write it. ;-)
            >
            >--
            >Martin Cooper
            >

            _________________________________________________________________
            Advertisement: Fresh jobs daily. Stop waiting for the newspaper. Search Now!
            www.seek.com.au
            http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fninemsn%2Eseek%2Ecom%2Eau&_t=757263760&_r=Hotmail_EndText_Dec06&_m=EXT
          • Jesse Skinner
            It sounds like you want to use a JavaScript object, with your uniqueID column as the key. What you d do is somehow structure your JSON like so: { uniqueID1 :
            Message 5 of 19 , Dec 10, 2006
            • 0 Attachment
              It sounds like you want to use a JavaScript object, with your uniqueID
              column as the key. What you'd do is somehow structure your JSON like so:

              {
              "uniqueID1": {
              "EM": 12,
              ......
              "Y": 136
              },

              "uniqueID2": {
              "EM": 5,
              ......
              "Y": 188
              },
              }

              then if this object is JSON, you could access JSON['uniqueID1'].EM where
              uniqueID1 is of course one of your unique IDs.

              If you really want to keep your JSON structure, you could loop over it
              once and create a JavaScript object like I've illustrated, and use that
              instead for your lookups.

              Hope that helps,

              Jesse Skinner
              http://www.thefutureoftheweb.com/

              Mark Ireland wrote:
              > Here is one I prepared earlier:
              >
              > {"RECORDCOUNT":30,"COLUMNLIST":"EM,EY,ISSILO,ISWEATHER,LATITUDE,LONGITUDE,PERCENTCOMPLETE,PERCENTQUALITY,SM,UNIQUEID,STATIONNAME,SY,X,Y","DATA":{"EM":[12,5,12,4,10,10,10,10,10,10,10,10,10,10,10,12,10,10,9,12,11,11,12,12,12,10,10,9,3,10],"EY":[2005,2005,2005,2006,2006,2006,2006,2006,2006,2006,2006,2006,2006,2006,2006,2006,2006,.
              >
              > . . . . . .
              > .....,"X":[291,28,152,171,109,96,268,126,250,123,174,188,199,251,91,238,147,274,97,274,126,167,100,145,207,146,120,160,241,232],"Y":[136,188,197,226,212,211,128,113,126,179,197,175,176,148,51,147,252,153,66,180,224,158,83,73,122,131,151,250,178,134]}};
              >
              > I could just loop through this testing for my uniqueID but surely someone
              > has written something quicker and more reusable than that? Is this not a
              > standard structure?
              >
            • Martin Cooper
              ... Depends on how you define standard , but no, it s not anything I would call a standard. I believe it s a format that comes from the CFJSON library, so
              Message 6 of 19 , Dec 10, 2006
              • 0 Attachment
                On 12/10/06, Mark Ireland <markincuba@...> wrote:
                >
                > Here is one I prepared earlier:
                >
                >
                > {"RECORDCOUNT":30,"COLUMNLIST":"EM,EY,ISSILO,ISWEATHER,LATITUDE,LONGITUDE,PERCENTCOMPLETE,PERCENTQUALITY,SM,UNIQUEID,STATIONNAME,SY,X,Y","DATA":{"EM":[12,5,12,4,10,10,10,10,10,10,10,10,10,10,10,12,10,10,9,12,11,11,12,12,12,10,10,9,3,10],"EY":[2005,2005,2005,2006,2006,2006,2006,2006,2006,2006,2006,2006,2006,2006,2006,2006,2006,.
                > . . . . . .
                >
                > .....,"X":[291,28,152,171,109,96,268,126,250,123,174,188,199,251,91,238,147,274,97,274,126,167,100,145,207,146,120,160,241,232],"Y":[136,188,197,226,212,211,128,113,126,179,197,175,176,148,51,147,252,153,66,180,224,158,83,73,122,131,151,250,178,134]}};
                >
                > I could just loop through this testing for my uniqueID but surely someone
                > has written something quicker and more reusable than that? Is this not a
                > standard structure?


                Depends on how you define "standard", but no, it's not anything I would call
                a standard. I believe it's a format that comes from the CFJSON library, so
                that would be the place to look for helper code to access the data.

                --
                Martin Cooper


                >From: "Martin Cooper" <mfncooper@...>
                > >Reply-To: json@yahoogroups.com
                > >To: json@yahoogroups.com
                > >Subject: Re: [json] json as js variable
                > >Date: Sun, 10 Dec 2006 14:13:22 -0800
                > >
                > >On 12/10/06, Mark Ireland <markincuba@...> wrote:
                > > >
                > > >
                > > > Thanks. I was hoping there was a js function library where you just
                > pass
                > > > the
                > > > unique id and the row is returned.
                > > > Is there one?
                > >
                > >
                > >What do you mean? There is no concept of "row" in JSON, or even unique
                > IDs,
                > >for that matter, beyond the property names in an object. Any structure
                > you
                > >are imposing on your JSON objects is your own, so there isn't going to be
                > a
                > >library out there to manipulate that unless you write it. ;-)
                > >
                > >--
                > >Martin Cooper
                > >
                >
                > _________________________________________________________________
                > Advertisement: Fresh jobs daily. Stop waiting for the newspaper. Search
                > Now!
                > www.seek.com.au
                >
                > http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fninemsn%2Eseek%2Ecom%2Eau&_t=757263760&_r=Hotmail_EndText_Dec06&_m=EXT
                >
                >
                >
                >
                > Yahoo! Groups Links
                >
                >
                >
                >


                [Non-text portions of this message have been removed]
              • Mark Ireland
                OK Now I have this: var myStuff = {
                Message 7 of 19 , Dec 10, 2006
                • 0 Attachment
                  OK Now I have this:
                  var myStuff = {
                  "80020":{"EM":10,"EY":2006,"ISSILO":1,"ISWEATHER":1,"LATITUDE":-35.9661,"LONGITUDE":144.3712,"PERCENTCOMPLETE":100,"PERCENTQUALITY":0,"SM":7,"STATIONID":80020,"STATIONNAME":GUNBOWER
                  GEE TEE STUD,"SY":1910,"X":37,"Y":31},
                  "80044":{"EM":10,"EY":2006,"ISSILO":1,"ISWEATHER":1,"LATITUDE":-35.9977,"LONGITUDE":144.4244,"PERCENTCOMPLETE":100,"PERCENTQUALITY":0,"SM":6,"STATIONID":80044,"STATIONNAME":PATHO
                  WEST,"SY":1920,"X":55,"Y":41},....
                  "80056":{"EM":10,"EY":2006,"ISSILO":0,"ISWEATHER":1,"LATITUDE":-36.2497,"LONGITUDE":144.9531,"PERCENTCOMPLETE":90,"PERCENTQUALITY":0,"SM":1,"STATIONID":80056,"STATIONNAME":TONGALA,"SY":1929,"X":232,"Y":126}
                  };

                  but I get "missing } after property list" before I have even done anything
                  with it.

                  >From: Jesse Skinner <jesse@...>
                  >Reply-To: json@yahoogroups.com
                  >To: json@yahoogroups.com
                  >Subject: Re: [json] json as js variable
                  >Date: Sun, 10 Dec 2006 18:04:05 -0500
                  >
                  >It sounds like you want to use a JavaScript object, with your uniqueID
                  >column as the key. What you'd do is somehow structure your JSON like so:
                  >
                  >{
                  > "uniqueID1": {
                  > "EM": 12,
                  > ......
                  > "Y": 136
                  > },
                  >
                  > "uniqueID2": {
                  > "EM": 5,
                  > ......
                  > "Y": 188
                  > },
                  >}
                  >
                  >then if this object is JSON, you could access JSON['uniqueID1'].EM where
                  >uniqueID1 is of course one of your unique IDs.
                  >
                  >If you really want to keep your JSON structure, you could loop over it
                  >once and create a JavaScript object like I've illustrated, and use that
                  >instead for your lookups.
                  >
                  >Hope that helps,
                  >
                  >Jesse Skinner
                  >http://www.thefutureoftheweb.com/
                  >

                  _________________________________________________________________
                  Advertisement: Meet Sexy Singles Today @ Lavalife - Click here
                  http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Flavalife9%2Eninemsn%2Ecom%2Eau%2Fclickthru%2Fclickthru%2Eact%3Fid%3Dninemsn%26context%3Dan99%26locale%3Den%5FAU%26a%3D23769&_t=754951090&_r=endtext_lavalife_dec_meet&_m=EXT
                • Matthew Morley
                  *Identifiers* are names for constants, variables, functions, loop labels, objects and classes. The first character must be an ASCII letter, underscore or
                  Message 8 of 19 , Dec 11, 2006
                  • 0 Attachment
                    *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]
                  • Mark Ireland
                    Thanks, that got it working. Now I am wondering if there is some alternative to repeating the column names in every object. ...
                    Message 9 of 19 , Dec 17, 2006
                    • 0 Attachment
                      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@...>
                      >Reply-To: json@yahoogroups.com
                      >To: json@yahoogroups.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&referral=million&URL=http://live.com.au
                    • Matthew Morley
                      Why not return an object w/ 2 properties. One being an array containing field names, the other being an array of arrays, representing data records (that match
                      Message 10 of 19 , Dec 17, 2006
                      • 0 Attachment
                        Why not return an object w/ 2 properties.

                        One being an array containing field names, the other being an array of
                        arrays, representing data records (that match the field layout).

                        Or the second object setup with properties named after the u80020, but still
                        being just an array of fields in that object.

                        --
                        Matthew P. C. Morley
                        MPCM Technologies Inc.


                        [Non-text portions of this message have been removed]
                      • Mark Ireland
                        How would you use dot notation in each case? ... _________________________________________________________________ Advertisement: Fresh jobs daily. Stop
                        Message 11 of 19 , Dec 17, 2006
                        • 0 Attachment
                          How would you use dot notation in each case?

                          >From: "Matthew Morley" <WickedLogic@...>
                          >Reply-To: json@yahoogroups.com
                          >To: json@yahoogroups.com
                          >Subject: Re: [json] json as js variable
                          >Date: Sun, 17 Dec 2006 22:10:06 -0500
                          >
                          >Why not return an object w/ 2 properties.
                          >
                          >One being an array containing field names, the other being an array of
                          >arrays, representing data records (that match the field layout).
                          >
                          >Or the second object setup with properties named after the u80020, but
                          >still
                          >being just an array of fields in that object.
                          >
                          >--
                          >Matthew P. C. Morley
                          >MPCM Technologies Inc.
                          >
                          >
                          >[Non-text portions of this message have been removed]
                          >

                          _________________________________________________________________
                          Advertisement: Fresh jobs daily. Stop waiting for the newspaper. Search Now!
                          www.seek.com.au
                          http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Fninemsn%2Eseek%2Ecom%2Eau&_t=757263760&_r=Hotmail_EndText_Dec06&_m=EXT
                        • Matthew Morley
                          You would have to do something more than a simple translation. If your end goal was to directly reference fields values by name, you would need to do an end
                          Message 12 of 19 , Dec 18, 2006
                          • 0 Attachment
                            You would have to do something more than a simple translation.

                            If your end goal was to directly reference fields values by name, you would
                            need to do an end translation back to the object format in which you were
                            trying to avoid by duplicating names. Just a loop to recreate the data
                            object from the two arrays.

                            You have the knowledge of the fields names and could do your looping in
                            another manner, without direct reference anyway. Depends how exposed it is I
                            suppose and what level of work you want consumers of the data to do/know. I
                            found gzip an easier alternative than object rebuilding when looking at
                            performance in my projects

                            Depending on the size of your data and lots of other items, it is likely to
                            be faster for transmitting due to reduced payload, but it requires you to
                            deal with the arrays and not objects unless you rebuild them.

                            var row = MyStuff.u80020;
                            var field_ISWEATHER = 3;
                            var val = MyStuff.u80020[field_ISWEATHER];

                            --
                            Matthew P. C. Morley
                            MPCM Technologies Inc.


                            [Non-text portions of this message have been removed]
                          • Mark Ireland
                            Hopefully I can clear all this up. First I wanted to save on whitespace by avoiding var myArray = new Array; cfloop var myArray[myIndex] = new Array;
                            Message 13 of 19 , Dec 18, 2006
                            • 0 Attachment
                              Hopefully I can clear all this up. First I wanted to save on whitespace by
                              avoiding
                              var myArray = new Array;
                              cfloop
                              var myArray[myIndex] = new Array;
                              myArray[myIndex]['mycolumnName1']=#myQuery.myColumn1#;
                              myArray[myIndex]['mycolumnName2']=#myQuery.myColumn2#;
                              etc
                              /cfloop

                              Then I thought I could dynamically name form elements and get stuff from a
                              js object that I could reference with dot notation. (with myIndex as the id
                              of the element) Most of the stuff in the object is just flags that determine
                              how the page behaves.

                              If my goal is the shrink the page size what is the better approach?

                              Thanks


                              >From: "Matthew Morley" <WickedLogic@...>
                              >Reply-To: json@yahoogroups.com
                              >To: json@yahoogroups.com
                              >Subject: Re: [json] json as js variable
                              >Date: Mon, 18 Dec 2006 06:50:37 -0500
                              >
                              >You would have to do something more than a simple translation.
                              >
                              >If your end goal was to directly reference fields values by name, you would
                              >need to do an end translation back to the object format in which you were
                              >trying to avoid by duplicating names. Just a loop to recreate the data
                              >object from the two arrays.
                              >
                              >You have the knowledge of the fields names and could do your looping in
                              >another manner, without direct reference anyway. Depends how exposed it is
                              >I
                              >suppose and what level of work you want consumers of the data to do/know. I
                              >found gzip an easier alternative than object rebuilding when looking at
                              >performance in my projects
                              >
                              >Depending on the size of your data and lots of other items, it is likely to
                              >be faster for transmitting due to reduced payload, but it requires you to
                              >deal with the arrays and not objects unless you rebuild them.
                              >
                              >var row = MyStuff.u80020;
                              >var field_ISWEATHER = 3;
                              >var val = MyStuff.u80020[field_ISWEATHER];
                              >
                              >--
                              >Matthew P. C. Morley
                              >MPCM Technologies Inc.
                              >
                              >
                              >[Non-text portions of this message have been removed]
                              >

                              _________________________________________________________________
                              Advertisement: Meet Sexy Singles Today @ Lavalife - Click here
                              http://a.ninemsn.com.au/b.aspx?URL=http%3A%2F%2Flavalife9%2Eninemsn%2Ecom%2Eau%2Fclickthru%2Fclickthru%2Eact%3Fid%3Dninemsn%26context%3Dan99%26locale%3Den%5FAU%26a%3D23769&_t=754951090&_r=endtext_lavalife_dec_meet&_m=EXT
                            • Matthew Morley
                              It would depend on what you mean by page and how much data you are dealing with. 3-10kb range might not make a huge difference on download, 20-300kb might. Run
                              Message 14 of 19 , Dec 19, 2006
                              • 0 Attachment
                                It would depend on what you mean by page and how much data you are dealing
                                with. 3-10kb range might not make a huge difference on download, 20-300kb
                                might. Run some tests and time them in js, just keep in mind that they will
                                vary from machine to machine greatly. I keep a 433mhz celeron laptop around
                                to make sure I don't lose sight of performance too much.

                                If you are worried about transmission speed and you have a fairly big set of
                                data going, consider sizing it down. I know it sounds simple, but the
                                fastest way to speed up anything is to do less; less data, less parsing.
                                Don't optimize and worry about speed until you can prove it is running
                                slowly and that the program is only `thinking` as much as it needs to.

                                If that is not possible or desired, look at compressing the output with
                                something like gzip if the browser supports it, but the numbers all get down
                                to your data set. Using objects vs an object with an array of results and an
                                array of keys is just a matter for the code/coder. Depends who your consumer
                                is. If you want an object, send an object, and compress the communication
                                would be my stance.

                                Are you generating raw js right into the initial page? If yes, consider
                                moving it out into a separate request. That way you can do initial loads and
                                refresh with the data as it becomes available.

                                --
                                Matthew P. C. Morley
                                MPCM Technologies Inc.


                                [Non-text portions of this message have been removed]
                              • Atif Aziz
                                I think I know what you re looking for here. Suppose the following table: var table = { columns : [ FirstName , LastName ], rows : [ [ Mickey , Mouse
                                Message 15 of 19 , Dec 19, 2006
                                • 0 Attachment
                                  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>
                                • Mark Ireland
                                  This is the right general idea but . . ... I am thinking: var myJSObject =
                                  Message 16 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.