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

JSON Prob

Expand Messages
  • alvinz_c
    Hi, i have a json data like var celldata = [ {firstcell: yyy ,secondcell: xxx }, {firstcell: yyy ,secondcell: xxx }, {firstcell: yyy ,secondcell: xxx } ]; By
    Message 1 of 4 , Jan 7, 2006
      Hi, i have a json data like

      var celldata = [ {firstcell:"yyy",secondcell:"xxx"},

      {firstcell:"yyy",secondcell:"xxx"},

      {firstcell:"yyy",secondcell:"xxx"}
      ];


      By calling celldata.length would return 3 (3 rows), but how do I call
      so that it could determine the number of "columns", which supposed
      return 2 (firstcell and secondcell) ?


      Thanks !
    • MPCM
      celldata is an array of objects, each object having 2 properties. You can loop through the properties and count, but I m not sure if there is a function that
      Message 2 of 4 , Jan 7, 2006
        celldata is an array of objects, each object having 2 properties.

        You can loop through the properties and count, but I'm not sure if there is
        a function that will return the flat count. If there is, I haven't run
        across it yet online. It is crude, and I'd love to see a better way.

        Something like
        var i=0;
        for(var prop in celldata[0]){i++;}
        --
        Matt


        [Non-text portions of this message have been removed]
      • alvinz_c
        Thanks for your suggestion. It works !! Thanks .... :) ... there is ... run ... way.
        Message 3 of 4 , Jan 8, 2006
          Thanks for your suggestion. It works !! Thanks .... :)



          --- In json@yahoogroups.com, MPCM <WickedLogic@g...> wrote:
          >
          > celldata is an array of objects, each object having 2 properties.
          >
          > You can loop through the properties and count, but I'm not sure if
          there is
          > a function that will return the flat count. If there is, I haven't
          run
          > across it yet online. It is crude, and I'd love to see a better
          way.
          >
          > Something like
          > var i=0;
          > for(var prop in celldata[0]){i++;}
          > --
          > Matt
          >
          >
          > [Non-text portions of this message have been removed]
          >
        • Atif Aziz
          Bear in mind that the following... ... [ {firstcell: yyy ,secondcell: xxx }, {firstcell: yyy ,secondcell: xxx }, {firstcell: yyy ,secondcell: xxx } ]
          Message 4 of 4 , Jan 12, 2006
            Bear in mind that the following...

            >>
            [ {firstcell:"yyy",secondcell:"xxx"},
            {firstcell:"yyy",secondcell:"xxx"},
            {firstcell:"yyy",secondcell:"xxx"} ]
            <<

            ...is not valid JSON. Technically, it is valid JavaScript, but for you
            to call it JSON data (as per the spec), you mush double-quote the
            property names as well (just like strings). That is, all occurrences of
            firstcell and secondcell must be literally expressed as "firstcell" and
            "secondcell". See also message #187 [1] for more on this.

            [1] http://groups.yahoo.com/group/json/message/187

            -----Original Message-----
            From: json@yahoogroups.com [mailto:json@yahoogroups.com] On Behalf Of
            alvinz_c
            Sent: Sunday, January 08, 2006 3:37 AM
            To: json@yahoogroups.com
            Subject: [json] JSON Prob

            Hi, i have a json data like

            var celldata = [ {firstcell:"yyy",secondcell:"xxx"},

            {firstcell:"yyy",secondcell:"xxx"},

            {firstcell:"yyy",secondcell:"xxx"}
            ];


            By calling celldata.length would return 3 (3 rows), but how do I call
            so that it could determine the number of "columns", which supposed
            return 2 (firstcell and secondcell) ?


            Thanks !






            Yahoo! Groups Links
          Your message has been successfully submitted and would be delivered to recipients shortly.
          »
          «