简体   繁体   English

在javascript中解析类似json的结构/字符串

[英]parse json-like structure/string in javascript

I have this variable: 我有这个变量:

var txt = { 
    'e3fe40': { 
        'name' : 'Menu2',
        'data': {
            'prompt_say' : 'Thank you for calling ',
            'keys[]' : ['1','2'],
            'choices[]' : [
                'start/e3fe40/d2d27',
                'start/e3fe40/77c197'
            ]...

While I can parse with no problems things such as txt[position].data .... , I cannot seem to be able to parse these two: 虽然我可以毫无问题地解析txt[position].data ....之类的东西,但似乎无法解析这两个:

txt[position].data.keys and txt[position].data.choices txt[position].data.keystxt[position].data.choices

(last two entries from code above) (以上代码的最后两个条目)

I tried with 我尝试过

txt[position].data.keys[1], 
txt[position].data.keys[],
txt[position].data.keys

etc. 等等

None worked. 没有工作。 I always get "undefined" value. 我总是得到"undefined"值。

Any ideas? 有任何想法吗?

txt[position].data['keys[]']

The key keys[] is the name of the key. keys[]keys[]的名称。 You can't arbitrarily insert JSON-like strings in as a key name and expect it to parse. 您不能随意将类似JSON的字符串作为键名插入并期望它进行解析。 This obviously assumes that the value of position is e3fe40 or whatever it needs to be. 显然,这假定position值为e3fe40或所需的任何值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM