/    Sign up×
Community /Pin to ProfileBookmark

Access Object name that is a number

I have a php script that returns on array as JSON. I then eval the JSON to make it into an object which I then want to use.

The problem here is that my sever is sending an array that has id’s in it, which makes the name of the javascript objects numbers, which when trying to print, it does not seem to work.

So, using the following:

[CODE]var json = ‘{“43”:{“48”:{“id”:”48″}}}’;
json = eval(‘(‘ + json + ‘)’);
document.write(json.43.48.id);[/CODE]

Firebug tells me:

[CODE]missing ) after argument list[/CODE]

So, is it just not possible to have numbers as names in an object? Not really sure how I could change this, as my server sends it this way…guess I could try to tweak the array before it gets sent if this needs to be done.

Ideas?

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@Jeff_MottJul 08.2009 — json["43"]["48"].id
Copy linkTweet thisAlerts:
@nnhubbardauthorJul 08.2009 — json["43"]["48"].id[/QUOTE]

Thank you! That worked.

So, why did I have to do it that way instead of just stringing them together? Because they are numbers?
×

Success!

Help @nnhubbard spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...