Author Topic: Duplicate keys  (Read 1144 times)

Nick_W

  • Full Member
  • ***
  • Posts: 215
    • View Profile
Duplicate keys
« on: January 21, 2017, 07:23:12 pm »
I'm just getting ready to release my new LIS2DH12 library (which actually works), and I'm writing some example programs.

One thing I ran into, was putting a line like this into the accelerometer ISR

Code: [Select]
JData.add("Orientation", Orientation)

Where jData is a json object, and Orientation is a string giving the Orientation "up" "down" etc. The json is published ever 10 seconds by a shared event.

The json object is a shared variable, and is cleared after it is published.

I thought that as the orientation was changed, the new orientation would overwrite the old, and when published you would have the orientation at the point it was published.

Instead, I get a run time error, saying that the publish string is too long. Looking at the culprit (jData) it has dozens of entries (I couldn't tell what the entries were, the Debugger shows (" for the content, but the Count() was 120 in one instance.

This seems to imply that duplicate pairs are allowed in a json object (and the standard does not disallow this).

Is this the case? Is this the intended operation of your implementation of the json object?

It's an easy fix (just clear before adding the new value), but I was wondering if this was intended or not, as most json implementations do not allow duplicate keys.

I also ran this through slowly, to see how duplicate keys deserialize to strings, and lo! No duplicate keys in the string. But the count says there is. Not sure exactly what is going on.

Share on Facebook Share on Twitter