I have created a json object from ruby with cobravsmongoose, however the attributes have the '@' symbol in front of them. Whenever I try to access them with standard object notation in JavaScript, such as object.object.object.@attribute I get a parse error. Is there another way to access these objects?
+1
A:
Grab your JSON as a string instead. Do a replace to clean up the @ symbols, and recreate it as JSON.
Diodeus
2008-10-30 20:34:56
Wouldn't that be very CPU intensive either in Ruby, or in JavaScript on the client. Wouldn't it be better to just modify the library?
Heat Miser
2008-10-31 03:20:49
It's just a simple string replace. I'd do it on the client. Unless you're getting a megabyte of data it will take milliseconds. There's no complexity in the data to dance through yet - it's just a blob of text.
Diodeus
2008-10-31 20:07:04
+1
A:
You can also access your object attributes with subscript notation:
object.object['@attribute']
But it's better to do as @Diodeus proposed
Damir Zekić
2008-10-30 20:37:30