PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WINDEV 2024 → JSON Data Structure
JSON Data Structure
Débuté par ech madriaga, 24 nov. 2015 07:22 - 4 réponses
Posté le 24 novembre 2015 - 07:22
Hi All,

I need your advice.
How I can change/modify the original or current output number 1 to the structure in Number 2. I need to put and "Enter Command" after "[" and before "]".

1. Original Output - [{"id":1,"type":"Model","modelName":"Model Name","assettype":{"id":1,"type":"AssetType"},"manufacturer":{"id":1,"type":"Manufacturer"},"warrantyType":{"id":1,"type":"WarrantyType"}}]

2. Final Output - [
{
"id":1,
"type":"Model",
"modelName":"Model Name",
"assettype":{"id":1,"type":"AssetType"},
"manufacturer":{"id":1,"type":"Manufacturer"},
"warrantyType":{"id":1,"type":"WarrantyType"}
}
]
Posté le 25 novembre 2015 - 08:00
Your JSON represents an object but objectes a not supportted by JSONToVariant/VariantTOJSON. Try to convert object to associative array - remove framing [].
Posté le 25 novembre 2015 - 14:24
Hi Arekusei,

Can you help me about this.
-Removing of framing []
-Convert object to associative array

Thanks,
Ech
Posté le 25 novembre 2015 - 15:17
Ech,

for WD20:

This will work fine with the variant. Use the power of the debugger to see how the variant is constructed to use it later on in your for each loop.

[attachment 1779 screen1.png]

You see that the JSON structure is converted to the Variant

If you use this code (Code from the 'convert' button)

sJsonData is string = EDT_NoName1 vMyData is Variant = JSONToVariant(sJsonData) TableDeleteAll(TABLE_NoName1) FOR EACH line OF vMyData TableAddLine(TABLE_NoName1,line.modelName,line.type) END
you will get this output:
[attachment 1780 screen2.png]

You will have to use the correct statements to get the dynamic data from the variant.

So it is very easy to work with JSON data.

Another way is to define a structure that represents your Json data and use deserialize to fill the structure from you JSON data, but this is more complex but it depends on the what you need the data for.

Hope this helps !
Danny
Posté le 26 novembre 2015 - 10:14
Excellent!!
Thank you Danny Lauwers.

Now, I had done for displaying the information from json.
Can you help me on how I can add, modify, and delete a information using json?
Do you have any samples?

Thanks,
Ech