How can I access a value from a Json file inside a matlab function?

5 次查看(过去 30 天)
Hi guys,
I am running R2013a with Jsonlab plugin, and here is my problem:
I am creating a function which retrieves the value attached to a key inside a Json file. The inputs to my function are the Json file and the key, and the output should be the value (with a specific formatting)
But here is the thing: I usually access the value by writing " filename.key ", but since here the key is input as a string in the function, the program behaves as if I was calling " filename.'key' " and returns me the following error "Reference to non-existent field 'key' "
Any idea on how to go around this issue?
  1 个评论
simon poiret
simon poiret 2016-3-3
Ok, problem solved!
The trick is to add parenthesis around the key, like that:
"filename.(key)" instead of "filename.key"
Then it also works with "filename.('key')"
It might help someone else.

请先登录,再进行评论。

回答(0 个)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by