views:

30

answers:

1

I am using the services module in drupal a long with the JSON Server, and I am accessing it using jQuery this works great, but I have one small problem.

Drupal/JSON Server always seem to return objects with the # symbol, which I don't really know how to handle, this prevents me from doing

object.property

Because in reality it's object.#property but obviously javascript gives error here, so should I just run a regex and replace the "#" symbols or what do I do?

Example, I invoke some method using a jQuery post, and it returns data such as, a console.log would spit out this:

Object
#data: Object
#error: true
#message: "Already logged in as admin."
__proto__: Object
#error: false
__proto__: Object

Now it works great it returns the data I need etc, but I want to be able todo:

object.message , but it wont let me because of the # and I can't do object.#message

So either javascript have some funny thing built in for this, or I need to delete all the "#" but that does not seem like such a good solution to me, don't ask me why drupal returns objects with this symbol as part of the name, I suppose it has some kind of use or meaning but I have yet to understand that

Forgive my ignorance if it's something "obvious" :D

Also I suppose a regex would just make my app slower if these are big json objects/strings so rather not, right?

Thanks!

+1  A: 

You can always use object['#message'] when the property name has weird characters like that.

I don't know anything about Drupal but if I were in that situation I'd certainly try to figure out how to get it to quit sending weird JSON back to me like that.

Pointy
Yeah exactly, well I looked at the module code (PHP) and they just generate the objects like that, I can easily get rid of the "#" but, I keep thinking there must be some reason for them to have it.
quiggle