Problem with multidimensionnal JSON object

  • Thread starter Roger (Bordeaux)
  • Start date
R

Roger (Bordeaux)

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":"2006-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>
 
M

Martin Honnen

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));
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,818
Latest member
Brigette36

Latest Threads

Top