By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,609 Members | 3,812 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,609 IT Pros & Developers. It's quick & easy.

JSON array problem

P: n/a
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
Oct 24 '08 #1
Share this Question
Share on Google+
2 Replies


P: n/a
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
Oct 24 '08 #2

P: n/a
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
Oct 24 '08 #3

This discussion thread is closed

Replies have been disabled for this discussion.