In the following statement, how could I make the "log.entries[i]" part a variable?
json.log.entries[i]
eval works but I don’t want to use it.
eval("json" + "var")
I also tried:
json[var]
Thanks
In the following statement, how could I make the "log.entries[i]" part a variable?
json.log.entries[i]
eval works but I don’t want to use it.
eval("json" + "var")
I also tried:
json[var]
Thanks
You would have to split it up like this:
json["log"]["entries"][i];
But honestly I think that eval really would be your best option for a situation like this. Why do you need to store this as a string? Perhaps if I knew more about the problem you are trying to solve I could give you a btter solution.
It sounds like the target variable you're trying to refer to is "jsonvariablename", and not a property of an object called "json" which could be referred json.variablename / json[variablename]. This is not a good naming structure for variables and eval is indeed required in this case -- is it possible for you to change the variable format so that the variables are properties of an object called JSON? That would be the best solution.