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

5 Ansichten (letzte 30 Tage)
simon poiret
simon poiret am 3 Mär. 2016
Kommentiert: simon poiret am 3 Mär. 2016
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 Kommentar
simon poiret
simon poiret am 3 Mär. 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.

Melden Sie sich an, um zu kommentieren.

Antworten (0)

Community Treasure Hunt

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

Start Hunting!

Translated by