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

5 views (last 30 days)
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 Comment
simon poiret
simon poiret on 3 Mar 2016
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.

Sign in to comment.

Answers (0)

Community Treasure Hunt

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

Start Hunting!