Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - Problema lettura stringa json
Forum - C# / VB.NET - Problema lettura stringa json

Pagine: [ 1 2 3 ] Precedente | Prossimo
Avatar
Thejuster (Admin)
Guru^2


Messaggi: 2331
Iscritto: 04/05/2008

Segnala al moderatore
Postato alle 20:16
Giovedì, 30/05/2024
Buonasera ragazzi.
Ho un problema con la lettura di questa stringa in json

Codice sorgente - presumibilmente C# / VB.NET

  1. [
  2. null,
  3. {"id":1,"list":[{"code":355,"indent":0,"parameters":["TestUI();"]},{"code":0,"indent":0,"parameters":[]}],"name":"CallUI","switchId":1,"trigger":0},
  4. {"id":2,"list":[{"code":0,"indent":0,"parameters":[]}],"name":"","switchId":1,"trigger":0},
  5. {"id":3,"list":[{"code":0,"indent":0,"parameters":[]}],"name":"","switchId":1,"trigger":0},
  6. {"id":4,"list":[{"code":0,"indent":0,"parameters":[]}],"name":"","switchId":1,"trigger":0}
  7. ]



Dovrei leggerla in c++ ma mi va bene uguale in C#. dopo converto il codice per adattarlo alle librerie.
Il problema sta che non riesco a recuperare i campi all'id 1
come vedete, gli array di id:2, id:3, id:4 sono uguali, il primo e diverso.
quello che devo recuperare, è sattamente situato dopo la parentesi quadra. ]
mi serve ottenere

"name":"CallUI"

non riesco in nessun modo.
Qualcuno sà come fare? grazie in anticipo.


https://mire.forumfree.it/ - Mire Engine
C# UI Designer
PM Quote
Avatar
Carlo (Member)
Guru


Messaggi: 1388
Iscritto: 29/01/2018

Segnala al moderatore
Postato alle 22:42
Giovedì, 30/05/2024
Se hai il problema ad interpretare la collocazione di parametri valori ed indici, puoi usare la libreria json per C#:
https://www.nuget.org/packages/Newtonsoft.Json/

In allegato un semplice progetto in C# che la usa per scompattare la tua stringa.
Una volta identificate le modalià di indendazione puoi creare la tua routine personalizzata che estrae il valore di interesse sottostando alle regole di codifica Json scoperte.

Il progetto completo di libreria NuGet, supera i 2 Mbyte consentiti, l'ho caricato in dropbox:
https://www.dropbox.com/scl/fi/30np6h4dpnwnjq807zt9v/Json.z ...

Oppure con indexof, ma poi non so se funziona in tutte le situazioni, di sicuro funziona se il name che ti interessa è sempre dopo id:1
Codice sorgente - presumibilmente C#

  1. string jsonString = @"[null,
  2. {""id"":1,""list"":[{""code"":355,""indent"":0,""parameters"":[""TestUI();""]},{""code"":0,""indent"":0,""parameters"":[]}],""name"":""CallUI"",""switchId"":1,""trigger"":0},
  3. {""id"":2,""list"":[{""code"":0,""indent"":0,""parameters"":[]}],""name"":"""",""switchId"":1,""trigger"":0},
  4. {""id"":3,""list"":[{""code"":0,""indent"":0,""parameters"":[]}],""name"":"""",""switchId"":1,""trigger"":0},
  5. {""id"":4,""list"":[{""code"":0,""indent"":0,""parameters"":[]}],""name"":"""",""switchId"":1,""trigger"":0}]";
  6.  
  7. int pos1 = jsonString.IndexOf(@"""id"":1,");
  8. if (pos1 != -1) pos1 = jsonString.IndexOf(@"""name""", pos1);
  9. int pos2 = jsonString.IndexOf(",", pos1);
  10. if (pos1 != -1) Console.WriteLine(jsonString.Substring(pos1, pos2-pos1));


Ultima modifica effettuata da Carlo il 30/05/2024 alle 23:59


in programmazione tutto è permesso
PM Quote
Avatar
Thejuster (Admin)
Guru^2


Messaggi: 2331
Iscritto: 04/05/2008

Segnala al moderatore
Postato alle 0:30
Venerdì, 31/05/2024
Provo grazie mille. In ogni caso, non serve solo l'id 1 ma esempio, più un utente realizzerà elementi più name con contenuti diversi ci saranno.
Sicuramente il valore 0 va saltato ovvero nulla.

per dire:
se ora è così avendo name solo su id 1,


[
null,
{"id":1,"list":[{"code":355,"indent":0,"parameters":["TestUI();"]},{"code":0,"indent":0,"parameters":[]}],"name":"CallUI","switchId":1,"trigger":0},

{"id":2,"list":[{"code":0,"indent":0,"parameters":[]}],"name":"","switchId":1,"trigger":0},
{"id":3,"list":[{"code":0,"indent":0,"parameters":[]}],"name":"","switchId":1,"trigger":0},
{"id":4,"list":[{"code":0,"indent":0,"parameters":[]}],"name":"","switchId":1,"trigger":0}
]


in seguito potrebbe esserci name su tutti e quattro elementi o anche di piu.

Ultima modifica effettuata da Thejuster il 31/05/2024 alle 7:23


https://mire.forumfree.it/ - Mire Engine
C# UI Designer
PM Quote
Avatar
Carlo (Member)
Guru


Messaggi: 1388
Iscritto: 29/01/2018

Segnala al moderatore
Postato alle 10:34
Venerdì, 31/05/2024
Testo quotato

Postato originariamente da Thejuster:

Provo grazie mille. In ogni caso, non serve solo l'id 1 ma esempio, più un utente realizzerà elementi più name con contenuti diversi ci saranno.
Sicuramente il valore 0 va saltato ovvero nulla.



La libreria Json rispetta tutte le regole Json e funziona per tutte le implementazioni Json.

Se non vuoi utilizzare la libreria, una volta analizzate le variabili in gioco nelle tue possibili stringhe Json, puoi con IndexOf costruirti il tuo parser Json che funziona per il tuo caso specifico.

Ecco un esempio per cercare tutti gli id ed i rispettivi name contenuti nella tua stringa Json:

Codice sorgente - presumibilmente C#

  1. string jsonString = @"[null,
  2. {""id"":1,""list"":[{""code"":355,""indent"":0,""parameters"":[""TestUI();""]},{""code"":0,""indent"":0,""parameters"":[]}],""name"":""CallUI"",""switchId"":1,""trigger"":0},
  3. {""id"":2,""list"":[{""code"":0,""indent"":0,""parameters"":[]}],""name"":"""",""switchId"":1,""trigger"":0},
  4. {""id"":3,""list"":[{""code"":0,""indent"":0,""parameters"":[]}],""name"":"""",""switchId"":1,""trigger"":0},
  5. {""id"":4,""list"":[{""code"":0,""indent"":0,""parameters"":[]}],""name"":"""",""switchId"":1,""trigger"":0}]";
  6.  
  7. int pos1 = 0;
  8. int pos2 = 0;
  9. int id = 0;
  10. while (pos1 != -1)
  11. {
  12.    id++;
  13.    pos1 = jsonString.IndexOf(@"""id"":" + id.ToString() + ",");
  14.    if (pos1 != -1)
  15.    {
  16.        pos1 = jsonString.IndexOf(@"""name""", pos1);
  17.  
  18.        if (pos1 != -1)
  19.        {
  20.            pos2 = jsonString.IndexOf(",", pos1);
  21.            Console.WriteLine($"id:{id} {jsonString.Substring(pos1, pos2 - pos1)}");
  22.        }
  23.    }
  24. }



I name vuoti vanno gestiti, un solo name sotto lo stesso id, viene valutato.

Posta le stringhe Json che contengono più name sotto lo stesso id.

Ultima modifica effettuata da Carlo il 31/05/2024 alle 12:37


in programmazione tutto è permesso
PM Quote
Avatar
Thejuster (Admin)
Guru^2


Messaggi: 2331
Iscritto: 04/05/2008

Segnala al moderatore
Postato alle 22:21
Venerdì, 31/05/2024
non penso sia la soluzione migliore questa carlo.
int pos1 = 0;
int pos2 = 0;
int id = 0;

ti mostro un'altro esempio.

Questo qui, era piccolo. essendo un file autogenerato.
Penso che ci sia un problema di base proprio per questo tipo di file.

guarda quest'altro.

Nel programma che lo legge ( non il mio ) funziona senza problemi.

Se provo ad usare un validator online da errore
mentre per il programma è corretto

Codice sorgente - presumibilmente C# / VB.NET

  1. {}[
  2. null,
  3. {"id":1,"list":[{"code":356,"indent":0,"parameters":["mv3d camera mode perspective"]},{"code":356,"indent":0,"parameters":["mv3d pitch 60 1"]},{"code":355,"indent":0,"parameters":["const yaw = mz3d.blendCameraYaw.targetValue();"]},{"code":655,"indent":0,"parameters":["if((yaw+45)%90===0){mz3d.command('camera yaw',yaw-45,1);}"]},{"code":655,"indent":0,"parameters":["else if(yaw%90){mz3d.command('camera yaw',Math.round(yaw/90)*90,1);}"]},{"code":356,"indent":0,"parameters":["mv3d dist 5 1"]},{"code":356,"indent":0,"parameters":["mv3d zoom 1 1"]},{"code":0,"indent":0,"parameters":[]}],"name":"perspective: normal","switchId":1,"trigger":0},
  4. {"id":2,"list":[{"code":356,"indent":0,"parameters":["mv3d camera mode perspective"]},{"code":356,"indent":0,"parameters":["mv3d camera target @player 1"]},{"code":356,"indent":0,"parameters":["mv3d pitch 90 1"]},{"code":111,"indent":0,"parameters":[6,-1,8]},{"code":356,"indent":1,"parameters":["mv3d yaw 0 1"]},{"code":0,"indent":1,"parameters":[]},{"code":412,"indent":0,"parameters":[]},{"code":111,"indent":0,"parameters":[6,-1,4]},{"code":356,"indent":1,"parameters":["mv3d yaw 90 1"]},{"code":0,"indent":1,"parameters":[]},{"code":412,"indent":0,"parameters":[]},{"code":111,"indent":0,"parameters":[6,-1,2]},{"code":356,"indent":1,"parameters":["mv3d yaw 180 1"]},{"code":0,"indent":1,"parameters":[]},{"code":412,"indent":0,"parameters":[]},{"code":111,"indent":0,"parameters":[6,-1,6]},{"code":356,"indent":1,"parameters":["mv3d yaw 270 1"]},{"code":0,"indent":1,"parameters":[]},{"code":412,"indent":0,"parameters":[]},{"code":356,"indent":0,"parameters":["mv3d dist 0 1"]},{"code":356,"indent":0,"parameters":["mv3d zoom 1 1"]},{"code":0,"indent":0,"parameters":[]}],"name":"perspective: 1st person","switchId":1,"trigger":0},
  5. {"id":3,"list":[{"code":108,"indent":0,"parameters":["Cambia Texture a player"]},{"code":408,"indent":0,"parameters":["mv3d &#65312;p configure model(char.glb, textures:{ {./img/characters/Actor2.png,25%,0,100%,100%} })"]},{"code":108,"indent":0,"parameters":["<mz3d:model(char.glb,textures:{{./img/characters/People1.png,25%,100%,100%,100%}})>"]},{"code":408,"indent":0,"parameters":[""]},{"code":408,"indent":0,"parameters":["25% , 100%   (Ultima posizione in alto a destra)"]},{"code":408,"indent":0,"parameters":[""]},{"code":408,"indent":0,"parameters":["0 0 0 X"]},{"code":408,"indent":0,"parameters":["0 0 0 0"]},{"code":108,"indent":0,"parameters":["<mz3d:model(char.glb,textures:{{./img/characters/People4.png,100%,100%,100%,100%}})>"]},{"code":408,"indent":0,"parameters":[""]},{"code":408,"indent":0,"parameters":["100% , 100%   (Ultima posizione in alto a destra)"]},{"code":408,"indent":0,"parameters":[""]},{"code":408,"indent":0,"parameters":["0 0 X 0"]},{"code":408,"indent":0,"parameters":["0 0 0 0"]},{"code":108,"indent":0,"parameters":["<mz3d:model(char.glb,textures:{{./img/characters/People4.png,75%,100%,100%,100%}})>"]},{"code":408,"indent":0,"parameters":[""]},{"code":408,"indent":0,"parameters":["75% , 100%  "]},{"code":408,"indent":0,"parameters":[""]},{"code":408,"indent":0,"parameters":["0 X 0 0"]},{"code":408,"indent":0,"parameters":["0 0 0 0"]},{"code":108,"indent":0,"parameters":["<mz3d:model(char.glb,textures:{{./img/characters/People4.png,50%,100%,100%,100%}})>"]},{"code":408,"indent":0,"parameters":[""]},{"code":408,"indent":0,"parameters":["50% , 100%  "]},{"code":408,"indent":0,"parameters":[""]},{"code":408,"indent":0,"parameters":["X 0 0 0"]},{"code":408,"indent":0,"parameters":["0 0 0 0"]},{"code":108,"indent":0,"parameters":["<mz3d:model(char.glb,textures:{{./img/characters/People1.png,25%,100%,100%,100%}})>"]},{"code":408,"indent":0,"parameters":[""]},{"code":408,"indent":0,"parameters":["75% , 50%   (Ultima posizione in basso a destra)"]},{"code":408,"indent":0,"parameters":[""]},{"code":408,"indent":0,"parameters":["0 0 0 0"]},{"code":408,"indent":0,"parameters":["0 0 0 X"]},{"code":108,"indent":0,"parameters":["<mz3d:model(char.glb,textures:{{./img/characters/People4.png,50%,50%,100%,100%}})>"]},{"code":408,"indent":0,"parameters":[""]},{"code":408,"indent":0,"parameters":["25% 50%"]},{"code":408,"indent":0,"parameters":[""]},{"code":408,"indent":0,"parameters":["0 0 0 0"]},{"code":408,"indent":0,"parameters":["0 0 X 0"]},{"code":108,"indent":0,"parameters":["<mz3d:model(char.glb,textures:{{./img/characters/People4.png,25%,50%,100%,100%}})>"]},{"code":408,"indent":0,"parameters":[""]},{"code":408,"indent":0,"parameters":["100%,50%,100%,100%"]},{"code":408,"indent":0,"parameters":[""]},{"code":408,"indent":0,"parameters":["0 0 0 0"]},{"code":408,"indent":0,"parameters":["0 X 0 0"]},{"code":108,"indent":0,"parameters":["<mz3d:model(char.glb,textures:{{./img/characters/People4.png,100%,50%,100%,100%}})>"]},{"code":408,"indent":0,"parameters":[""]},{"code":408,"indent":0,"parameters":["100%,50%,100%,100%"]},{"code":408,"indent":0,"parameters":[""]},{"code":408,"indent":0,"parameters":["0 0 0 0"]},{"code":408,"indent":0,"parameters":["X 0 0 0"]},{"code":0,"indent":0,"parameters":[]}],"name":"Texture Personaggi","switchId":1,"trigger":0},
  6. {"id":4,"list":[{"code":356,"indent":0,"parameters":["mv3d camera zoom 1.3 1 "]},{"code":0,"indent":0,"parameters":[]}],"name":"Perspective Talk","switchId":1,"trigger":0},
  7. {"id":5,"list":[{"code":108,"indent":0,"parameters":["Add movement buttons on all maps"]},{"code":355,"indent":0,"parameters":["Galv.SBTNS.addButton(0,'map','BtnUp',80,500,['button','up']);"]},{"code":655,"indent":0,"parameters":["Galv.SBTNS.addButton(1,'map','BtnDown',80,630,['button','down']);"]},{"code":655,"indent":0,"parameters":["Galv.SBTNS.addButton(2,'map','BtnLeft',10,565,['button','left']);"]},{"code":655,"indent":0,"parameters":["Galv.SBTNS.addButton(3,'map','BtnRight',150,565,['button','right']);"]},{"code":108,"indent":0,"parameters":["Add action buttons on all maps"]},{"code":355,"indent":0,"parameters":["Galv.SBTNS.addButton(4,'map','BtnOk',900,550,['buttonT','ok']);"]},{"code":655,"indent":0,"parameters":["Galv.SBTNS.addButton(5,'map','BtnCancel',1100,550,['buttonT','cancel']);"]},{"code":655,"indent":0,"parameters":["//Galv.SBTNS.addButton(6,'map','BtnCancel',990,550,['button','shift']);"]},{"code":0,"indent":0,"parameters":[]}],"name":"Crea Comandi","switchId":1,"trigger":0},
  8. {"id":6,"list":[{"code":355,"indent":0,"parameters":["$gameSystem._hideBtns = false;"]},{"code":0,"indent":0,"parameters":[]}],"name":"Mostra Comandi","switchId":1,"trigger":0},
  9. {"id":7,"list":[{"code":355,"indent":0,"parameters":["$gameSystem._hideBtns = true;"]},{"code":0,"indent":0,"parameters":[]}],"name":"Nascondi Comandi","switchId":1,"trigger":0},
  10. {"id":8,"list":[{"code":356,"indent":0,"parameters":["mv3d camera dist 3 1"]},{"code":356,"indent":0,"parameters":["mv3d camera pitch +10 1"]},{"code":0,"indent":0,"parameters":[]}],"name":"Prospettiva Interni","switchId":1,"trigger":0},
  11. {"id":9,"list":[{"code":0,"indent":0,"parameters":[]}],"name":"","switchId":1,"trigger":0},
  12. {"id":10,"list":[{"code":108,"indent":0,"parameters":["//Danneggia nemico"]},{"code":408,"indent":0,"parameters":["action effect"]},{"code":408,"indent":0,"parameters":[""]},{"code":408,"indent":0,"parameters":["//Il nemico viene spinto in aria"]},{"code":408,"indent":0,"parameters":["jump target: 300, 60"]},{"code":0,"indent":0,"parameters":[]}],"name":"--battaglia","switchId":1,"trigger":0},
  13. {"id":11,"list":[{"code":356,"indent":0,"parameters":["mv3d &#65312;p configure model(char.glb,textures:{{./img/characters/Eliath.png,25%,100%,100%,100%}}),shadow(false)"]},{"code":0,"indent":0,"parameters":[]}],"name":"Eroe Trasparente","switchId":1,"trigger":0},
  14. {"id":12,"list":[{"code":356,"indent":0,"parameters":["mv3d &#65312;p configure model(char.glb, textures:{ {./img/characters/Eliath.png}}bones:{head:{scale:1}}actions:{run:{speed:1}}),shadow(true)"]},{"code":0,"indent":0,"parameters":[]}],"name":"Eroe Normale","switchId":1,"trigger":0},
  15. {"id":13,"list":[{"code":356,"indent":0,"parameters":["weather : 0 : 15 : 60 : 100 : 0 : Rain_01B"]},{"code":0,"indent":0,"parameters":[]}],"name":"== Pioggia ==","switchId":1,"trigger":0},
  16. {"id":14,"list":[{"code":356,"indent":0,"parameters":["weather : 0 : 22 : 14 : 30 : 0 : fogA"]},{"code":0,"indent":0,"parameters":[]}],"name":"== Nebbia ==","switchId":1,"trigger":0},
  17. {"id":15,"list":[{"code":356,"indent":0,"parameters":["clear_all_weathers"]},{"code":0,"indent":0,"parameters":[]}],"name":"= Rimuovi Clima =","switchId":1,"trigger":0},
  18. {"id":16,"list":[{"code":205,"indent":0,"parameters":[-1,{"list":[{"code":29,"parameters":[2],"indent":null},{"code":30,"parameters":[2],"indent":null},{"code":0}],"repeat":false,"skippable":false,"wait":true}]},{"code":505,"indent":0,"parameters":[{"code":29,"parameters":[2],"indent":null}]},{"code":505,"indent":0,"parameters":[{"code":30,"parameters":[2],"indent":null}]},{"code":0,"indent":0,"parameters":[]}],"name":"= IN MAPPA =","switchId":1,"trigger":0},
  19. {"id":17,"list":[{"code":205,"indent":0,"parameters":[-1,{"list":[{"code":29,"parameters":[4],"indent":null},{"code":30,"parameters":[3],"indent":null},{"code":0}],"repeat":false,"skippable":false,"wait":true}]},{"code":505,"indent":0,"parameters":[{"code":29,"parameters":[4],"indent":null}]},{"code":505,"indent":0,"parameters":[{"code":30,"parameters":[3],"indent":null}]},{"code":0,"indent":0,"parameters":[]}],"name":"= USCITA MAPPA =","switchId":1,"trigger":0}
  20. ]



Per i comuni parser json non funziona.
Ma stranamente posso assicurare che funziona.
visto che questo file viene letto anche da tree.js e pixi.js

Ultima modifica effettuata da Thejuster il 31/05/2024 alle 22:25


https://mire.forumfree.it/ - Mire Engine
C# UI Designer
PM Quote
Avatar
Carlo (Member)
Guru


Messaggi: 1388
Iscritto: 29/01/2018

Segnala al moderatore
Postato alle 0:02
Sabato, 01/06/2024
Ritengo che i programmatori abbiano usato un loro dialetto Json per adattarlo a delle esigenze specifiche, ma se ti scrivi il tuo parser, non hai problemi.

Il programma che ti ho proposto con IndexOf infatti estrae tutti i name da tutti gli id, senza problemi.
Ho inserito i caratteri di escape \" in sostituzione delle virgolette, invece delle doppie virgolette necessarie dopo la @, tale approcio rende la stringa fruibile anche in C:

Codice sorgente - presumibilmente C# / VB.NET

  1. string jsonString = "{}[null,{\"id\":1,\"list\":[{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d camera mode perspective\"]},{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d pitch 60 1\"]},{\"code\":355,\"indent\":0,\"parameters\":[\"const yaw = mz3d.blendCameraYaw.targetValue();\"]},{\"code\":655,\"indent\":0,\"parameters\":[\"if((yaw+45)%90===0){mz3d.command('camera yaw',yaw-45,1);}\"]},{\"code\":655,\"indent\":0,\"parameters\":[\"else if(yaw%90){mz3d.command('camera yaw',Math.round(yaw/90)*90,1);}\"]},{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d dist 5 1\"]},{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d zoom 1 1\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"perspective: normal\",\"switchId\":1,\"trigger\":0},{\"id\":2,\"list\":[{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d camera mode perspective\"]},{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d camera target @player 1\"]},{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d pitch 90 1\"]},{\"code\":111,\"indent\":0,\"parameters\":[6,-1,8]},{\"code\":356,\"indent\":1,\"parameters\":[\"mv3d yaw 0 1\"]},{\"code\":0,\"indent\":1,\"parameters\":[]},{\"code\":412,\"indent\":0,\"parameters\":[]},{\"code\":111,\"indent\":0,\"parameters\":[6,-1,4]},{\"code\":356,\"indent\":1,\"parameters\":[\"mv3d yaw 90 1\"]},{\"code\":0,\"indent\":1,\"parameters\":[]},{\"code\":412,\"indent\":0,\"parameters\":[]},{\"code\":111,\"indent\":0,\"parameters\":[6,-1,2]},{\"code\":356,\"indent\":1,\"parameters\":[\"mv3d yaw 180 1\"]},{\"code\":0,\"indent\":1,\"parameters\":[]},{\"code\":412,\"indent\":0,\"parameters\":[]},{\"code\":111,\"indent\":0,\"parameters\":[6,-1,6]},{\"code\":356,\"indent\":1,\"parameters\":[\"mv3d yaw 270 1\"]},{\"code\":0,\"indent\":1,\"parameters\":[]},{\"code\":412,\"indent\":0,\"parameters\":[]},{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d dist 0 1\"]},{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d zoom 1 1\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"perspective: 1st person\",\"switchId\":1,\"trigger\":0},{\"id\":3,\"list\":[{\"code\":108,\"indent\":0,\"parameters\":[\"Cambia Texture a player\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"mv3d &#65312;p configure model(char.glb, textures:{ {./img/characters/Actor2.png,25%,0,100%,100%} })\"]},{\"code\":108,\"indent\":0,\"parameters\":[\"<mz3d:model(char.glb,textures:{{./img/characters/People1.png,25%,100%,100%,100%}})>\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"25% , 100%   (Ultima posizione in alto a destra)\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 0 0 X\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 0 0 0\"]},{\"code\":108,\"indent\":0,\"parameters\":[\"<mz3d:model(char.glb,textures:{{./img/characters/People4.png,100%,100%,100%,100%}})>\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"100% , 100%   (Ultima posizione in alto a destra)\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 0 X 0\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 0 0 0\"]},{\"code\":108,\"indent\":0,\"parameters\":[\"<mz3d:model(char.glb,textures:{{./img/characters/People4.png,75%,100%,100%,100%}})>\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"75% , 100%  \"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 X 0 0\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 0 0 0\"]},{\"code\":108,\"indent\":0,\"parameters\":[\"<mz3d:model(char.glb,textures:{{./img/characters/People4.png,50%,100%,100%,100%}})>\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"50% , 100%  \"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"X 0 0 0\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 0 0 0\"]},{\"code\":108,\"indent\":0,\"parameters\":[\"<mz3d:model(char.glb,textures:{{./img/characters/People1.png,25%,100%,100%,100%}})>\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"75% , 50%   (Ultima posizione in basso a destra)\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 0 0 0\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 0 0 X\"]},{\"code\":108,\"indent\":0,\"parameters\":[\"<mz3d:model(char.glb,textures:{{./img/characters/People4.png,50%,50%,100%,100%}})>\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"25% 50%\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 0 0 0\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 0 X 0\"]},{\"code\":108,\"indent\":0,\"parameters\":[\"<mz3d:model(char.glb,textures:{{./img/characters/People4.png,25%,50%,100%,100%}})>\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"100%,50%,100%,100%\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 0 0 0\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 X 0 0\"]},{\"code\":108,\"indent\":0,\"parameters\":[\"<mz3d:model(char.glb,textures:{{./img/characters/People4.png,100%,50%,100%,100%}})>\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"100%,50%,100%,100%\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 0 0 0\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"X 0 0 0\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"Texture Personaggi\",\"switchId\":1,\"trigger\":0},{\"id\":4,\"list\":[{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d camera zoom 1.3 1 \"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"Perspective Talk\",\"switchId\":1,\"trigger\":0},{\"id\":5,\"list\":[{\"code\":108,\"indent\":0,\"parameters\":[\"Add movement buttons on all maps\"]},{\"code\":355,\"indent\":0,\"parameters\":[\"Galv.SBTNS.addButton(0,'map','BtnUp',80,500,['button','up']);\"]},{\"code\":655,\"indent\":0,\"parameters\":[\"Galv.SBTNS.addButton(1,'map','BtnDown',80,630,['button','down']);\"]},{\"code\":655,\"indent\":0,\"parameters\":[\"Galv.SBTNS.addButton(2,'map','BtnLeft',10,565,['button','left']);\"]},{\"code\":655,\"indent\":0,\"parameters\":[\"Galv.SBTNS.addButton(3,'map','BtnRight',150,565,['button','right']);\"]},{\"code\":108,\"indent\":0,\"parameters\":[\"Add action buttons on all maps\"]},{\"code\":355,\"indent\":0,\"parameters\":[\"Galv.SBTNS.addButton(4,'map','BtnOk',900,550,['buttonT','ok']);\"]},{\"code\":655,\"indent\":0,\"parameters\":[\"Galv.SBTNS.addButton(5,'map','BtnCancel',1100,550,['buttonT','cancel']);\"]},{\"code\":655,\"indent\":0,\"parameters\":[\"//Galv.SBTNS.addButton(6,'map','BtnCancel',990,550,['button','shift']);\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"Crea Comandi\",\"switchId\":1,\"trigger\":0},{\"id\":6,\"list\":[{\"code\":355,\"indent\":0,\"parameters\":[\"$gameSystem._hideBtns = false;\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"Mostra Comandi\",\"switchId\":1,\"trigger\":0},{\"id\":7,\"list\":[{\"code\":355,\"indent\":0,\"parameters\":[\"$gameSystem._hideBtns = true;\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"Nascondi Comandi\",\"switchId\":1,\"trigger\":0},{\"id\":8,\"list\":[{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d camera dist 3 1\"]},{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d camera pitch +10 1\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"Prospettiva Interni\",\"switchId\":1,\"trigger\":0},{\"id\":9,\"list\":[{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"\",\"switchId\":1,\"trigger\":0},{\"id\":10,\"list\":[{\"code\":108,\"indent\":0,\"parameters\":[\"//Danneggia nemico\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"action effect\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"//Il nemico viene spinto in aria\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"jump target: 300, 60\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"--battaglia\",\"switchId\":1,\"trigger\":0},{\"id\":11,\"list\":[{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d &#65312;p configure model(char.glb,textures:{{./img/characters/Eliath.png,25%,100%,100%,100%}}),shadow(false)\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"Eroe Trasparente\",\"switchId\":1,\"trigger\":0},{\"id\":12,\"list\":[{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d &#65312;p configure model(char.glb, textures:{ {./img/characters/Eliath.png}}bones:{head:{scale:1}}actions:{run:{speed:1}}),shadow(true)\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"Eroe Normale\",\"switchId\":1,\"trigger\":0},{\"id\":13,\"list\":[{\"code\":356,\"indent\":0,\"parameters\":[\"weather : 0 : 15 : 60 : 100 : 0 : Rain_01B\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"== Pioggia ==\",\"switchId\":1,\"trigger\":0},{\"id\":14,\"list\":[{\"code\":356,\"indent\":0,\"parameters\":[\"weather : 0 : 22 : 14 : 30 : 0 : fogA\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"== Nebbia ==\",\"switchId\":1,\"trigger\":0},{\"id\":15,\"list\":[{\"code\":356,\"indent\":0,\"parameters\":[\"clear_all_weathers\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"= Rimuovi Clima =\",\"switchId\":1,\"trigger\":0},{\"id\":16,\"list\":[{\"code\":205,\"indent\":0,\"parameters\":[-1,{\"list\":[{\"code\":29,\"parameters\":[2],\"indent\":null},{\"code\":30,\"parameters\":[2],\"indent\":null},{\"code\":0}],\"repeat\":false,\"skippable\":false,\"wait\":true}]},{\"code\":505,\"indent\":0,\"parameters\":[{\"code\":29,\"parameters\":[2],\"indent\":null}]},{\"code\":505,\"indent\":0,\"parameters\":[{\"code\":30,\"parameters\":[2],\"indent\":null}]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"= IN MAPPA =\",\"switchId\":1,\"trigger\":0},{\"id\":17,\"list\":[{\"code\":205,\"indent\":0,\"parameters\":[-1,{\"list\":[{\"code\":29,\"parameters\":[4],\"indent\":null},{\"code\":30,\"parameters\":[3],\"indent\":null},{\"code\":0}],\"repeat\":false,\"skippable\":false,\"wait\":true}]},{\"code\":505,\"indent\":0,\"parameters\":[{\"code\":29,\"parameters\":[4],\"indent\":null}]},{\"code\":505,\"indent\":0,\"parameters\":[{\"code\":30,\"parameters\":[3],\"indent\":null}]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"= USCITA MAPPA =\",\"switchId\":1,\"trigger\":0}]";
  2.  
  3.  
  4. int pos1 = 0;
  5. int pos2 = 0;
  6. int id = 0;
  7. while (pos1 != -1)
  8. {
  9.     id++;
  10.     pos1 = jsonString.IndexOf(@"""id"":" + id.ToString() + ",");
  11.     if (pos1 != -1)
  12.     {
  13.         pos1 = jsonString.IndexOf(@"""name""", pos1);
  14.  
  15.         if (pos1 != -1)
  16.         {
  17.             pos2 = jsonString.IndexOf(",", pos1);
  18.             Console.WriteLine($"id:{id} {jsonString.Substring(pos1, pos2 - pos1)}");
  19.         }
  20.     }
  21. }



Naturalmente anche altri parametri di interesse possono essere estratti.

Nel prossimo post ti invio lo stesso codice in C

Ultima modifica effettuata da Carlo il 01/06/2024 alle 0:03


in programmazione tutto è permesso
PM Quote
Avatar
Carlo (Member)
Guru


Messaggi: 1388
Iscritto: 29/01/2018

Segnala al moderatore
Postato alle 0:09
Sabato, 01/06/2024
Questo lo stesso codice in C con due subroutine comode comode, IndexOf e Substring, in modo da renderlo uguale a quello in C#

la stringa Json che hai postato anche qui è adattata con i caratteri di escape per permettere la rappresentazione delle virgolette interne:

Codice sorgente - presumibilmente C++

  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <stdlib.h>
  4.  
  5. // IndexOf come in C#
  6. int IndexOf(const char *str, const char *subStr, int startPos) {
  7.     int len = strlen(str);
  8.     int subLen = strlen(subStr);
  9.  
  10.     // parametri fuori range
  11.     if (startPos >= len || subLen == 0) return -1;
  12.  
  13.     // ricerca posizione sottostringa
  14.     for (int i = startPos; i <= len - subLen; i++) {
  15.         if (strncmp(&str[i], subStr, subLen) == 0) {
  16.             return i;
  17.         }
  18.     }
  19.     return -1; // non trovato
  20. }
  21.  
  22. // Substring come in C#
  23. char* Substring(const char *str, int startPos, int length) {
  24.     int strLength = strlen(str);
  25.  
  26.     // startPos fuori range
  27.     if (startPos < 0 || startPos >= strLength) {
  28.         return NULL;
  29.     }
  30.  
  31.     // fino alla fine se length è negativo o supera la lunghezza
  32.     if (length < 0 || startPos + length > strLength) {
  33.         length = strLength - startPos;
  34.     }
  35.  
  36.     // memoria per la sottostringa
  37.     char *subStr = (char*)malloc((length + 1) * sizeof(char));
  38.     if (subStr == NULL) return NULL; // memoria non allocata
  39.  
  40.     // Copia il segmento richiesto
  41.     strncpy(subStr, &str[startPos], length);
  42.     subStr[length] = '\0'; // terminatore
  43.  
  44.     return subStr;
  45. }
  46.  
  47. int main() {
  48.     const char *jsonString = "{}[null,{\"id\":1,\"list\":[{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d camera mode perspective\"]},{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d pitch 60 1\"]},{\"code\":355,\"indent\":0,\"parameters\":[\"const yaw = mz3d.blendCameraYaw.targetValue();\"]},{\"code\":655,\"indent\":0,\"parameters\":[\"if((yaw+45)%90===0){mz3d.command('camera yaw',yaw-45,1);}\"]},{\"code\":655,\"indent\":0,\"parameters\":[\"else if(yaw%90){mz3d.command('camera yaw',Math.round(yaw/90)*90,1);}\"]},{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d dist 5 1\"]},{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d zoom 1 1\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"perspective: normal\",\"switchId\":1,\"trigger\":0},{\"id\":2,\"list\":[{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d camera mode perspective\"]},{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d camera target @player 1\"]},{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d pitch 90 1\"]},{\"code\":111,\"indent\":0,\"parameters\":[6,-1,8]},{\"code\":356,\"indent\":1,\"parameters\":[\"mv3d yaw 0 1\"]},{\"code\":0,\"indent\":1,\"parameters\":[]},{\"code\":412,\"indent\":0,\"parameters\":[]},{\"code\":111,\"indent\":0,\"parameters\":[6,-1,4]},{\"code\":356,\"indent\":1,\"parameters\":[\"mv3d yaw 90 1\"]},{\"code\":0,\"indent\":1,\"parameters\":[]},{\"code\":412,\"indent\":0,\"parameters\":[]},{\"code\":111,\"indent\":0,\"parameters\":[6,-1,2]},{\"code\":356,\"indent\":1,\"parameters\":[\"mv3d yaw 180 1\"]},{\"code\":0,\"indent\":1,\"parameters\":[]},{\"code\":412,\"indent\":0,\"parameters\":[]},{\"code\":111,\"indent\":0,\"parameters\":[6,-1,6]},{\"code\":356,\"indent\":1,\"parameters\":[\"mv3d yaw 270 1\"]},{\"code\":0,\"indent\":1,\"parameters\":[]},{\"code\":412,\"indent\":0,\"parameters\":[]},{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d dist 0 1\"]},{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d zoom 1 1\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"perspective: 1st person\",\"switchId\":1,\"trigger\":0},{\"id\":3,\"list\":[{\"code\":108,\"indent\":0,\"parameters\":[\"Cambia Texture a player\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"mv3d &#65312;p configure model(char.glb, textures:{ {./img/characters/Actor2.png,25%,0,100%,100%} })\"]},{\"code\":108,\"indent\":0,\"parameters\":[\"<mz3d:model(char.glb,textures:{{./img/characters/People1.png,25%,100%,100%,100%}})>\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"25% , 100%   (Ultima posizione in alto a destra)\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 0 0 X\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 0 0 0\"]},{\"code\":108,\"indent\":0,\"parameters\":[\"<mz3d:model(char.glb,textures:{{./img/characters/People4.png,100%,100%,100%,100%}})>\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"100% , 100%   (Ultima posizione in alto a destra)\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 0 X 0\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 0 0 0\"]},{\"code\":108,\"indent\":0,\"parameters\":[\"<mz3d:model(char.glb,textures:{{./img/characters/People4.png,75%,100%,100%,100%}})>\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"75% , 100%  \"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 X 0 0\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 0 0 0\"]},{\"code\":108,\"indent\":0,\"parameters\":[\"<mz3d:model(char.glb,textures:{{./img/characters/People4.png,50%,100%,100%,100%}})>\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"50% , 100%  \"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"X 0 0 0\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 0 0 0\"]},{\"code\":108,\"indent\":0,\"parameters\":[\"<mz3d:model(char.glb,textures:{{./img/characters/People1.png,25%,100%,100%,100%}})>\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"75% , 50%   (Ultima posizione in basso a destra)\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 0 0 0\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 0 0 X\"]},{\"code\":108,\"indent\":0,\"parameters\":[\"<mz3d:model(char.glb,textures:{{./img/characters/People4.png,50%,50%,100%,100%}})>\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"25% 50%\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 0 0 0\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 0 X 0\"]},{\"code\":108,\"indent\":0,\"parameters\":[\"<mz3d:model(char.glb,textures:{{./img/characters/People4.png,25%,50%,100%,100%}})>\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"100%,50%,100%,100%\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 0 0 0\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 X 0 0\"]},{\"code\":108,\"indent\":0,\"parameters\":[\"<mz3d:model(char.glb,textures:{{./img/characters/People4.png,100%,50%,100%,100%}})>\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"100%,50%,100%,100%\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"0 0 0 0\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"X 0 0 0\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"Texture Personaggi\",\"switchId\":1,\"trigger\":0},{\"id\":4,\"list\":[{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d camera zoom 1.3 1 \"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"Perspective Talk\",\"switchId\":1,\"trigger\":0},{\"id\":5,\"list\":[{\"code\":108,\"indent\":0,\"parameters\":[\"Add movement buttons on all maps\"]},{\"code\":355,\"indent\":0,\"parameters\":[\"Galv.SBTNS.addButton(0,'map','BtnUp',80,500,['button','up']);\"]},{\"code\":655,\"indent\":0,\"parameters\":[\"Galv.SBTNS.addButton(1,'map','BtnDown',80,630,['button','down']);\"]},{\"code\":655,\"indent\":0,\"parameters\":[\"Galv.SBTNS.addButton(2,'map','BtnLeft',10,565,['button','left']);\"]},{\"code\":655,\"indent\":0,\"parameters\":[\"Galv.SBTNS.addButton(3,'map','BtnRight',150,565,['button','right']);\"]},{\"code\":108,\"indent\":0,\"parameters\":[\"Add action buttons on all maps\"]},{\"code\":355,\"indent\":0,\"parameters\":[\"Galv.SBTNS.addButton(4,'map','BtnOk',900,550,['buttonT','ok']);\"]},{\"code\":655,\"indent\":0,\"parameters\":[\"Galv.SBTNS.addButton(5,'map','BtnCancel',1100,550,['buttonT','cancel']);\"]},{\"code\":655,\"indent\":0,\"parameters\":[\"//Galv.SBTNS.addButton(6,'map','BtnCancel',990,550,['button','shift']);\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"Crea Comandi\",\"switchId\":1,\"trigger\":0},{\"id\":6,\"list\":[{\"code\":355,\"indent\":0,\"parameters\":[\"$gameSystem._hideBtns = false;\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"Mostra Comandi\",\"switchId\":1,\"trigger\":0},{\"id\":7,\"list\":[{\"code\":355,\"indent\":0,\"parameters\":[\"$gameSystem._hideBtns = true;\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"Nascondi Comandi\",\"switchId\":1,\"trigger\":0},{\"id\":8,\"list\":[{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d camera dist 3 1\"]},{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d camera pitch +10 1\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"Prospettiva Interni\",\"switchId\":1,\"trigger\":0},{\"id\":9,\"list\":[{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"\",\"switchId\":1,\"trigger\":0},{\"id\":10,\"list\":[{\"code\":108,\"indent\":0,\"parameters\":[\"//Danneggia nemico\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"action effect\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"//Il nemico viene spinto in aria\"]},{\"code\":408,\"indent\":0,\"parameters\":[\"jump target: 300, 60\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"--battaglia\",\"switchId\":1,\"trigger\":0},{\"id\":11,\"list\":[{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d &#65312;p configure model(char.glb,textures:{{./img/characters/Eliath.png,25%,100%,100%,100%}}),shadow(false)\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"Eroe Trasparente\",\"switchId\":1,\"trigger\":0},{\"id\":12,\"list\":[{\"code\":356,\"indent\":0,\"parameters\":[\"mv3d &#65312;p configure model(char.glb, textures:{ {./img/characters/Eliath.png}}bones:{head:{scale:1}}actions:{run:{speed:1}}),shadow(true)\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"Eroe Normale\",\"switchId\":1,\"trigger\":0},{\"id\":13,\"list\":[{\"code\":356,\"indent\":0,\"parameters\":[\"weather : 0 : 15 : 60 : 100 : 0 : Rain_01B\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"== Pioggia ==\",\"switchId\":1,\"trigger\":0},{\"id\":14,\"list\":[{\"code\":356,\"indent\":0,\"parameters\":[\"weather : 0 : 22 : 14 : 30 : 0 : fogA\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"== Nebbia ==\",\"switchId\":1,\"trigger\":0},{\"id\":15,\"list\":[{\"code\":356,\"indent\":0,\"parameters\":[\"clear_all_weathers\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"= Rimuovi Clima =\",\"switchId\":1,\"trigger\":0},{\"id\":16,\"list\":[{\"code\":205,\"indent\":0,\"parameters\":[-1,{\"list\":[{\"code\":29,\"parameters\":[2],\"indent\":null},{\"code\":30,\"parameters\":[2],\"indent\":null},{\"code\":0}],\"repeat\":false,\"skippable\":false,\"wait\":true}]},{\"code\":505,\"indent\":0,\"parameters\":[{\"code\":29,\"parameters\":[2],\"indent\":null}]},{\"code\":505,\"indent\":0,\"parameters\":[{\"code\":30,\"parameters\":[2],\"indent\":null}]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"= IN MAPPA =\",\"switchId\":1,\"trigger\":0},{\"id\":17,\"list\":[{\"code\":205,\"indent\":0,\"parameters\":[-1,{\"list\":[{\"code\":29,\"parameters\":[4],\"indent\":null},{\"code\":30,\"parameters\":[3],\"indent\":null},{\"code\":0}],\"repeat\":false,\"skippable\":false,\"wait\":true}]},{\"code\":505,\"indent\":0,\"parameters\":[{\"code\":29,\"parameters\":[4],\"indent\":null}]},{\"code\":505,\"indent\":0,\"parameters\":[{\"code\":30,\"parameters\":[3],\"indent\":null}]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"= USCITA MAPPA =\",\"switchId\":1,\"trigger\":0}]";
  49.  
  50.     int id = 0;
  51.     int pos1 = 0;
  52.     int pos2 = 0;
  53.     char searchStr[20]; // Buffer capiente per id fino a 16 cifre
  54.  
  55.     while (pos1 != -1) {
  56.         id++;
  57.         // sottostringa di ricerca
  58.         sprintf(searchStr, "\"id\":%d,", id); // stringa di ricerca = "id:1," quando id = 1
  59.  
  60.         pos1 = IndexOf(jsonString, searchStr, pos1);
  61.         if (pos1 != -1) {
  62.             pos1 = IndexOf(jsonString, "\"name\"", pos1); // stringa di ricerca = "name", il primo dopo id
  63.             if (pos1 != -1) {
  64.                 pos2 = IndexOf(jsonString, ",", pos1); // stringa di ricerca ",", la prima dopo name
  65.                 printf("id:%d %s\n", id, Substring(jsonString, pos1, pos2 - pos1));
  66.             }
  67.         }
  68.     }
  69.     return 0;
  70. }



Il programma fallirebbe se gli id non fossero progressivi, ma se ce ne fosse l'esigenza il codice è modificabile per un funzionamento anche con id random.

Tutto dipende da cosa vuoi estrarre e quali sono le regole da rispettare.

Ultima modifica effettuata da Carlo il 01/06/2024 alle 0:20


in programmazione tutto è permesso
PM Quote
Avatar
Thejuster (Admin)
Guru^2


Messaggi: 2331
Iscritto: 04/05/2008

Segnala al moderatore
Postato alle 8:34
Sabato, 01/06/2024
Ottimo grazie carlo funziona!

Ora mi tocca solo scrivere un metodo per modificare tutto file.
Nel senso aggiungere gli backslash

se è così
[
null,
{"id":1,"list":[{"code":355,"indent":0,"parameters":["TestUI();"]},{"code":0,"indent":0,"parameters":[]}],"name":"CallUI","switchId":1,"trigger":0},
{"id":2,"list":[{"code":0,"indent":0,"parameters":[]}],"name":"","switchId":1,"trigger":0},
{"id":3,"list":[{"code":0,"indent":0,"parameters":[]}],"name":"","switchId":1,"trigger":0},
{"id":4,"list":[{"code":0,"indent":0,"parameters":[]}],"name":"","switchId":1,"trigger":0}
]

deve diventare così

[null,{\"id\":1,\"list\":[{\"code\":355,\"indent\":0,\"parameters\":[\"TestUI();\"]},{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"CallUI\",\"switchId\":1,\"trigger\":0},{\"id\":2,\"list\":[{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"\",\"switchId\":1,\"trigger\":0},{\"id\":3,\"list\":[{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"\",\"switchId\":1,\"trigger\":0},{\"id\":4,\"list\":[{\"code\":0,\"indent\":0,\"parameters\":[]}],\"name\":\"\",\"switchId\":1,\"trigger\":0}]

Penso sia utile crearmi proprio una classe a parte.
e devo eliminare anche la parte che non mi interessa.
perché l'output che ricevo mi aggiunge i backslash


Teoricamente a me servirebbe solo  1  come identificativo e CallUI come metodo che saranno visibili nell'editor.
il problema sta leggendola da file.


Ultima modifica effettuata da Thejuster il 01/06/2024 alle 9:35


https://mire.forumfree.it/ - Mire Engine
C# UI Designer
PM Quote
Avatar
Thejuster (Admin)
Guru^2


Messaggi: 2331
Iscritto: 04/05/2008

Segnala al moderatore
Postato alle 11:01
Sabato, 01/06/2024
cmq niente non va.
Nel senso se scrivo manualmente la stringa, funziona.
Ma se provo in qualche modo a leggerlo da file mi salta i parametri


https://mire.forumfree.it/ - Mire Engine
C# UI Designer
PM Quote
Pagine: [ 1 2 3 ] Precedente | Prossimo