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