PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 25 → WD - Exemplo de desserializar um objeto JSON multinível (níveis de aninhamento)
WD - Exemplo de desserializar um objeto JSON multinível (níveis de aninhamento)
Débuté par BOLLER ADRIANO, 28 juin 2016 18:07 - 3 réponses
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 28 juin 2016 - 18:07
Exemplo:

Les codes free de FreeDev
[WinDev][20] Exemple de désérialisation d'un objet JSON multi-niveaux (imbrication de niveaux).

sJson2 est une chaîne ANSI = [
{
"messageId": "56f4c16e-b874-46b6-a548-09ec027bb6cf",
"from": "admin",
"creationUtcDate": "2015-04-06T12:02:48.56Z",
"who": {
"support": {
"status": 4,
"utcDate": "2015-04-06T20:44:21.643"
},
"technic": {
"status": 3,
"utcDate": "2015-04-06T20:44:21.656"
}
}
}
]

stMsgStamp est une structure
status est un entier
utcDate est une chaîne
FIN

who est une structure
support est un stMsgStamp
technic est un stMsgStamp
FIN

stMsg2 est une structure
messageId est une chaîne
from est une chaîne
creationUtcDate est une chaîne
who est un who
FIN

oMsg2 est un stMsg2

Désérialise(oMsg2,sJson2,psdJSON)


--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 9949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 11 août 2017 - 14:18
//-- le o arquivo Json anexado ao projeto --//
gsPerguntasJson is ANSI string = fLoadText( fDataDir()+"/questoes.json" )
gsPerguntasJson = UTF8ToAnsi(gsPerguntasJson)
//info(gsPerguntasJson)
//-----------------------------------------------------------------------------------------//
//-- agora coloca os dados em um array apos ler a estrrutura e grava na tabela Perguntas --//
//-----------------------------------------------------------------------------------------//

//--estrutura do Json
JsonStru is structure
pergunta is ANSI string
resp_a is ANSI string
resp_b is ANSI string
resp_c is ANSI string
resp_d is ANSI string
resp_e is ANSI string
resp_f is ANSI string
resp_g is ANSI string
resposta is ANSI string
explicacao is ANSI string
END



gstDadosJson is array of JsonStru
Deserialize( gstDadosJson , gsPerguntasJson , psdJSON)
//Info( ArrayCount(gstDadosJson))
//Info( gstDadosJson[1].pergunta )
FOR EACH st_linha_json OF gstDadosJson
Info(st_linha_json.explicacao)
END


--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/
Membre enregistré
123 messages
Popularité : +46 (46 votes)
Posté le 18 août 2017 - 15:32
Sempre é legal da creditos a quem fez/ajudou ou até mesmo desenvolveu o código, no caso acima eu fiz boa parte do mesmo, com as correções necesarias, inclusive teve outro membro que também colaborou nisso

--
Atte. Willian Fernando
Membre enregistré
3 651 messages
Popularité : +175 (223 votes)
Posté le 18 août 2017 - 17:10
ok

--
Adriano José Boller
______________________________________________
Consultor e Representante Oficial da
PcSoft no Brasil
+55 (41) 99949 1800
adrianoboller@gmail.com
skype: adrianoboller
http://wxinformatica.com.br/