Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

如何處理 JSON file 的key 裡有關鍵字 #2

Open
jarwow opened this issue May 28, 2016 · 0 comments
Open

如何處理 JSON file 的key 裡有關鍵字 #2

jarwow opened this issue May 28, 2016 · 0 comments
Labels

Comments

@jarwow
Copy link

jarwow commented May 28, 2016

問題情境如下:
我利用 nodejs call api 後得到一個 json file,我需要拆解 json file 後再拼成一個新的 json,
問題在api回來給我的API其中有一個key & values 長得像這樣
"#text": “/dev/watson”

我在取”#text” values的值時以這樣的方法取:
console.log(secContents.es_result.ibmsc_field[myKey].#text);

都會得到以下error:
console.log(secContents.es_result.ibmsc_field[myKey].#text);

SyntaxError: Unexpected token ILLEGAL
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:373:25)
at Object.Module._extensions..js (module.js:416:10)
at Module.load (module.js:343:32)

=================== 這是分隔線 ===================
[SOLUTION]

default
將code 從
console.log(secContents.es_result.ibmsc_field[myKey].#text);
改成
console.log(secContents.es_result.ibmsc_field[myKey]["#text"]);

@maoyang maoyang added the 問答 label May 28, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants