It is currently 8 June 2025, 22:29 Advanced search

ordine proprietà JSON.stringify

Domande e risposte su come utilizzare Instant Developer Foundation al meglio

ordine proprietà JSON.stringify

Postby r.bianco » 26 July 2024, 14:09

InDe 23.0 .NET 4, 64bit.

Abbiamo utilizzato lo standard JWT per verificare che il contenuto di un record non sia stato manomesso, magari accedendo direttamente al database.
Per farlo, abbiamo creato una mappa proprietà/valore delle proprietà 'importanti' e lo abbiamo passato a JSON.stringify.
Purtroppo, il json fornito da stringify ha le proprietà in un ordine differente in base alla macchina su cui l'applicazione è in esecuzione.
In questo modo, quando un'altra installazione riceve il record e ne verifica l'integrità, questa fallisce.

Da cosa dipende l'ordine con cui JSON.stringify tratta la mappa?
only work and no play makes jack a dull boy
r.bianco
 
Posts: 4979
Joined: 8 November 2010, 16:46

Re: ordine proprietà JSON.stringify

Postby d.pierangeli » 26 July 2024, 15:10

Non dipende da nulla esplicitamente, viene fatto

foreach (Object key in tbl.Keys) ...

tbl è una HashTable C# e keys è la sua collection.

E' in effetti possibile che su macchine diverse l'hashtable abbia ordini differenti.
User avatar
d.pierangeli
Pro Gamma
Pro Gamma
 
Posts: 8129
Joined: 30 September 2010, 15:35

Re: ordine proprietà JSON.stringify

Postby r.bianco » 26 July 2024, 15:27

Grazie.
only work and no play makes jack a dull boy
r.bianco
 
Posts: 4979
Joined: 8 November 2010, 16:46


Return to Tips & Tricks - Foundation

Who is online

Users browsing this forum: Google [Bot] and 30 guests