admin管理员组文章数量:1208155
I have created JSON by using the json_encode
PHP function. The key of one of the items of the array contains a forward slash and when the JSON is parsed, the object looks like this when output in Chrome's console.
Object
contact/allow_anonymous: "0"
menulayout: "horizontal"
pages/max_pages: "10"
primarycolour: "329e95"
websitelogo: "text"
My problem is that I can't seem to be able to access the value of the properties that have a forward slash in them.
Any ideas? Since javascript allowed me to create the object I would assume there is a way to retrieve the values.
I have created JSON by using the json_encode
PHP function. The key of one of the items of the array contains a forward slash and when the JSON is parsed, the object looks like this when output in Chrome's console.
Object
contact/allow_anonymous: "0"
menulayout: "horizontal"
pages/max_pages: "10"
primarycolour: "329e95"
websitelogo: "text"
My problem is that I can't seem to be able to access the value of the properties that have a forward slash in them.
Any ideas? Since javascript allowed me to create the object I would assume there is a way to retrieve the values.
Share Improve this question edited Nov 25, 2018 at 17:41 trincot 350k36 gold badges271 silver badges322 bronze badges asked Apr 25, 2012 at 17:43 Gabriel SpiteriGabriel Spiteri 4,97812 gold badges44 silver badges60 bronze badges 2 |2 Answers
Reset to default 21Just use myObject["key"]
instead of myObject.key
:
alert(myObject["contact/allow_anonymous"]);
Just replace the forward slash with ~1.
Instead of contact/allow_anonymous use contact~1allow_anonymous
本文标签: javascriptaccessing an object property that contains forward slashesStack Overflow
版权声明:本文标题:javascript - accessing an object property that contains forward slashes - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1738754772a2110606.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
myObject["contact/allow_anonymous"]
? – Tejs Commented Apr 25, 2012 at 17:44