PC SOFT

GRUPOS DE DISCUSSÃO PROFISSIONAL
WINDEVWEBDEV e WINDEV Mobile

Inicio → WINDEV 2024 → Json\variant  - delete member
Json\variant - delete member
Iniciado por Mark Crichton, mar., 22 2018 3:17 AM - 3 respostas
Publicado em março, 22 2018 - 3:17 AM
Hi
Can anyone help with deleting members for either Json on Variant.

I am updating invoices , and get Json from the API via Httprequest.
I then do JsonToVariant and make the changes to some of the members and now need to pass the Json back to the API via VariantToJson and all shoul dbe good.

How ever I need to delete certain memebrs that I must NOT pass back to the api.

Whats the easiest way to do this .

EG: vMyJson.RowID = 1224 needs to be deleted

looking for a member delete option ?
Membro registado
7 mensagems
Publicado em março, 09 2021 - 8:17 AM
Hello, did you find a way to do it ?

Thanks, Guy
Membro registado
56 mensagems
Popularité : +2 (2 votes)
Publicado em março, 09 2021 - 10:02 AM
Hello,
when you use JsonToVariant, your result is probably an array of variant.
So, have you tried to use ArrayDelete?

Example:

vMyVar is Variant

arrMyVar is array of Variant

vMyVar.Name="Paperino"
vMyVar.Address="Paperopoli"
ArrayAdd(arrMyVar,vMyVar)

vMyVar.Name="Topolino"
vMyVar.Address="Topolinia"
ArrayAdd(arrMyVar,vMyVar)

vMyVar.Name="Pippo"
vMyVar.Address="Topolinia"
ArrayAdd(arrMyVar,vMyVar)

vMyVar.Name="Pluto"
vMyVar.Address="Pippo's home"
ArrayAdd(arrMyVar,vMyVar)

MyJson is JSON=VariantToJSON(arrMyVar)

//MyJson has 4 elements

ArrayDelete(MyJson,3)

//MyJson has 3 elements

Hope this helps
Andrea
Publicado em novembro, 02 2023 - 3:04 PM
Hi,
A bit late, but here's how to do it for people finding this thread nowadays :
You have to use the ..Membre property of the variant; as it is an array containing all members, you can delete members using it.

myVar est un Variant
myVar.memb1 = "ToKeep"
myVar.memb2 = "ToDelete"

POUR TOUT myMember,ind de myvar..Membre
SI myMember..nom = "memb2" ALORS
Supprime(myVar..Membre,ind)
SORTIR
FIN
FIN