Closed pnaulls closed 8 years ago
Hi Just tried this. The property 'energy' is being added for the second time. This is not allowed with addProperty() which doesn't allow duplicates. If you want to update the value of the property that might or might not exist already, please use addOrModifyProperty()
Additional thought: I don't know if JSON allows duplicate keys in an object. I don't think Javascript does. jvar will simply fail to add the duplicate key entry. However, I am not certain if that is the best behavior.
Right. I hadn't spotted that. The problem for me is that this is produced from a device over which I have no control. So ideally I need a way to suppress this message (in this particular case), or have a flag to allow it.
FWIW, the PHP json parser doesn't have a problem with this.
I checked Javascript behavior. It allows adding duplicate properties without any errors/warnings. It simply updates the value to the latest value. I will change the jvar behavior to match that. I will do it this weekend.
With the following code:
I get:
Error: jvar/src/var.cpp(559): failed to add property with key 'energy'
Nevertheless, the value is there and correctly displayed/accessed within jvar.