JSON array problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • xdevel1999

    JSON array problem

    Hi, I have the following problem:
    when I try to access to the array in Big object I have 'Big is not
    defined'
    but
    when I try to access to the function in Low object I have no error!!!!
    WHY??

    Big =

    {
    One: [1, 2, 4],
    Two: [1, Big.One, 5]

    };

    alert(Big.Tow) // error

    Low =
    {
    One: function()
    {

    },
    Two: function()
    {
    Low.One();
    }
    };

    Low.Two(); // no error

    Thank


  • Conrad Lender

    #2
    Re: JSON array problem

    On 2008-10-24 11:42, xdevel1999 wrote:
    Hi, I have the following problem:
    when I try to access to the array in Big object I have 'Big is not
    defined'
    but
    when I try to access to the function in Low object I have no error!!!!
    WHY??
    None of these are valid JSON objects; that's the main problem.

    To answer your question: in the first case, 'Big' is not defined when
    you try to access it (which is in the line "[1, Big.One, 5]"). In the
    second case, 'Low' _is_ defined when you try to access it, which is in
    the line "Low.Two(); ".


    - Conrad

    Comment

    • Conrad Lender

      #3
      Re: JSON array problem

      On 2008-10-24 13:02, xdevel1999 wrote:
      >None of these are valid JSON objects; that's the main problem.
      >
      why is the syntax incorrect?
      First of all, JSON is a text format. What you're using are object
      literals. The JSON syntax is very simple, and completely described on
      this page: http://www.json.org/

      (in short: there are no functions and no references in JSON strings)
      Yes I can understand but this works...I'm confused
      >
      Low =
      {
      One: function()
      {
      alert(Low.b); // here the object Low is not already defined!
      True, but this line isn't executed yet. It will only be executed when
      you call the function. In your earlier example, Big.One would be
      evaluated immediately, before the interpreter knows what "Big" is.


      - Conrad

      Comment

      Working...