473,382 Members | 1,202 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

Problem with multidimensionnal JSON object

Hello,

You will find behind an example of the problem.

The defined JSON object is multidimentinnal.

The "weeks" object contains a serie of dates with week number and
monday's date.

I want to write a loop to display the dates. But the alert(typeof(b))
answer 'string' in place of 'object' and I can't access to the dates.

What's wrong ??

Thanks in advance for your help.

Roger
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta http-equiv="content-type" content="text/html;
charset=windows-1250">
<meta name="generator" content="PSPad editor, www.pspad.com">
<title></title>
<script type="text/javascript">

Object.display = function(object) {
resp = '';
for (property in object) {
resp += property + ' : ' + object[property]+"<br/>";
}
return resp;
}

var jsonObject =
{"2":{"name":"Xavier","weeks":{"01":{"date":"20 06-01-02"},"02":{"date":"2006-01-09"}}}};

for (a in jsonObject) {

alert(Object.display(jsonObject[a].weeks));

for (b in jsonObject[a].weeks) {
alert(typeof(b));
}
}

</script>
</head>
<body>

</body>
</html>
Oct 6 '06 #1
1 1305


Roger (Bordeaux) wrote:

I want to write a loop to display the dates. But the alert(typeof(b))
answer 'string' in place of 'object' and I can't access to the dates.
for (b in jsonObject[a].weeks) {
alert(typeof(b));
for..in enumerates the property names which are always strings so there
is nothing wrong with what you see. If you want the type of the property
value then you need to access e.g.
alert(typeof(jsonObject[a].weeks[b]));

--

Martin Honnen
http://JavaScript.FAQTs.com/
Oct 6 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
by: Luke Matuszewski | last post by:
Welcome As suggested i looked into JSON project and was amazed but... What about cyclical data structures - anybody was faced it in some project ? Is there any satisactional recomendation... ...
2
by: Kevin Newman | last post by:
Hello, I noticed that the JavaScript library for JSON posted on json.org (http://www.json.org/json.js) is modifying Object.prototype (adding a method - toJSONString). I thought this was...
3
by: Tom Cole | last post by:
I'm new to JSON but see how it can be an improvement over XML for some things. I've modified a test servlet to return the following string with a content type of text/x-json: { header: {...
2
by: bylabylamo | last post by:
i have a problem converting a json string that i get from a servlet into a json object using eval function of java script. any one please help me..........
15
RMWChaos
by: RMWChaos | last post by:
In my ongoing effort to produce shorter, more efficient code, I have created a "chicken and egg" / "catch-22" problem. I can think of several ways to fix this, none of them elegant. I want my code...
1
by: Pugi! | last post by:
Hi, I am using javascript to collect the user input from a form, put it in an object, json encode it (using JSON or YUI JSON), use the YUI connection manager (XMLHTTPRequest) to send it to a PHP...
9
by: Jon Paal [MSMD] | last post by:
using json like ( {"Records": , "RecordCount":"1" } ) and jquery like: $.ajax({ .... success: function(json, status) {
2
by: xdevel1999 | last post by:
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?? ...
0
by: JonTwend | last post by:
I am working with the Twitter API and finding it great fun and generally easy to use. But I am having trouble getting to the data in the trends/current.json file. I am able to loop through the...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.