JSON Text Decode reverses key and value

Hello everyone,
I receive from my ESP32 by Bluetooth a JSON Data of the form :

[{"id":1,"altiButeeH":14},{"id":2,"altiButeeB":87}]

image


The reception JSON Data is good: key "id" first, then sensor key second as in my Arduino code: "altiSun", "zenith"
On the other hand, once decoded by "CallWeb1.JsonTextDecode" it reclassified in the table all the keys in alphabetical order so I have an exchange of keys for keys not starting with "a": it put id first, then "parking" (and "zenith") second.

in the ListView1 it display the index of position 1 which does not give me the expected keys.
How to force "CallWeb1.JsonTextDecode" to decode in the order of the keys / values ​​received?

I would like to avoid adding extensions to keep the code easy to understand because ...
P.S I am a beginner in Mit app, I learn quickly but you have to explain to me for a long time lol
Cheers
Chris

Please post your ESP32 code too.

It's hard to determine the logical structure of your data from the overly short data stream sample.

here it is:

String message = "memoires:["
               "{\"id\":1,\"altiButeeH\":" + String(altiButeeH) + "},"
               "{\"id\":2,\"altiButeeB\":" + String(altiButeeB) + "},"
               "{\"id\":3,\"aziButeeO\":" + String(aziButeeO) + "},"
               "{\"id\":4,\"aziButeeE\":" + String(aziButeeE) + "},"
               "{\"id\":5,\"aziOffset\":" + String(aziOffset) + "},"
               "{\"id\":6,\"altiOffset\":" + String(altiOffset) + "},"
               "{\"id\":7,\"aziPanelFloat\":" + String(aziPanelFloat) + "},"
               "{\"id\":8,\"altiPanelFloat\":" + String(altiPanelFloat) + "},"
               "{\"id\":9,\"altiSun\":" + String(altiSun) + "},"
               "{\"id\":10,\"altiPanel\":" + String(altiPanel) + "},"
               "{\"id\":11,\"aziSun\":" + String(aziSun) + "},"
               "{\"id\":12,\"aziPanel\":" + String(aziPanel) + "},"
               "{\"id\":13,\"aziVitesseSlide\":" + String(aziVitesseSlide) + "},"
               "{\"id\":14,\"altiVitesseSlide\":" + String(altiVitesseSlide) + "},"
               "{\"id\":15,\"aziVitesse\":" + String(aziVitesse) + "},"
               "{\"id\":16,\"altiVitesse\":" + String(altiVitesse) + "},"
               "{\"id\":17,\"parkingPosi\":" + String(parkingPosi) + "},"
               "{\"id\":19,\"zenith\":" + String(zenith) + "}"
               "]";

      Serial.print("affMemoires ");
      Serial.println(message);
      sendBluetoothMessage(message);  //========> TX Bluetooth

And the sendBluetoothMessage function :

void sendBluetoothMessage(const String& message) {
   SerialBT.print(message);
   SerialBT.print('\n');  // Ajout d'une nouvelle ligne pour plus de clarté
}  

to retrieve global value, I split the message at the first ":". I deduce the complete JSON message: [{"id":1,"altiButeeH":14},{"id":2,"altiButeeB":87}....] as seen in lab_jsonData.

What do you want to show in your listview ? The records are still in the same order (by id number) after decoding

Besides the ListView presentation, how do you want to accumulate the data?

  • List of lists (table) structure with prescribed column order from the 19 row IDs, with a header row?
  • List of dictionaries, each with 19 attributes?

look at the first object: {"id":1,"altiButeeH":10}
Translation => [["altiButeeH",10],["id":1]] because "a" is placed before "i"
1st index of the list => (altiButeeH 10). Perfect.

Iook at the last object: {"id":19,"zenith":25}
Translation => [["id",19],["zenith":25]] because "i" is placed before "z"
1st index of the list => (id 19) . Bad

It seems that the translation puts in first place in the Array , the first of the 2 objects in alphabetical order: alti..., azi..., id.
Imagine if I had an object {"key":1,"deviceWest":10}
Translate => [["deviceWest",10],["key":1]] because "d" is before "k"
1st index => (deviceWest 10)

Obviously the final step is to display a dynamic table whose number of lines varies with the payload:
image
But I wanted to keep it simple at the beginning to understand what I was doing and not stupidly copy/paste. :smile:
Once again without using extensions (if possible).

image
superNinja.aia (3.4 KB)

This can order the ListView Elements by id number.

1 Like

Also, see here: