Bruce MacKay wrote:
> Hi folks,
>
> I don't understand what I'm doing wrong in the following code (
> http://temporarius.massey.ac.nz/json_test.htm) where I cannot seem to
> "harvest" the returned json string.
>
> The test json string being returned after the form is submitted is:
>
> {"fields": [{"id": "name",
> "isValid": false, "message": "Username must be
> at least 3 characters long"}]}
> I don't understand why the length of "fields" is being given as 1, and
> when I try to view the components of fields, I get an [object Object] error.
json.fields is an Array containing just one Object.
fields:
[ <-- An array
{ <-- An object
id: 'name', <-- A property
isValid: false,
...
}
]
If you want fields to contain an object, and you wish to iterate through
the properties of that object then you need to get rid of the array:
fields:
{
id: 'name',
isValid: false,
...
}
for (var propertyName in json.fields) {
alert(propertyName + ' = ' + json.fields[propertyName]);
}
Regards
- Mark
_______________________________________________
jQuery mailing list
[email protected]
http://jquery.com/discuss/