开发者

drupal json server, objects with ## symbol in javascript?

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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜