PC SOFT

FORUMS PROFESSIONNELS
WINDEVWEBDEV et WINDEV Mobile

Accueil → WEBDEV 21 → JSONToVariant
JSONToVariant
Débuté par Mister RUAN, 22 fév. 2017 10:22 - 5 réponses
//hostimage.webdev.info/avatars/SMNMuGqoaBbhEqRO8r9MMA
Membre enregistré
151 messages
Popularité : +1 (1 vote)
Posté le 22 février 2017 - 10:22
Good day

I have a json that cannot be fully parsed. Can you tell me what I am missing here please. Here is the code I am using:

sJson_dados is string = EDT_DETAILS

let dados_json=JSONToVariant(sJson_dados)

FOR EACH _m OF dados_json..Member

TableAddLine(TABLE_NoName1,_m..Name,_m..Value)
dados_json_itens(_m)
END


INTERNAL Procedure dados_json_itens(_itens)
FOR EACH _m2 OF _itens..Member
TableAddLine(TABLE_NoName1,_m2.rnum,_m2.sku,_m2.model,_m2.category,_m2.price)
END
END


And here is the JSON Data:

{"totalSize":57599,"nextRecordsUrl":"http://api-qas.technogym.com:8080/V1.0/pricebooks/78f05333be1990966f181bc65c529a67","records":[{"rnum":1,"sku":"0B000001","model":"0B000001","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":7.74,"descriptions":[{"ISOLanguageCode":"en","name":"SPACER 25,5x36x116,5","description":"SPACER 25,5x36x116,5"}]},{"rnum":2,"sku":"0B000002","model":"0B000002","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":6.15,"descriptions":[{"ISOLanguageCode":"en","name":"SPACER 25,5x35x46,5","description":"SPACER 25,5x35x46,5"}]},{"rnum":3,"sku":"0B000003","model":"0B000003","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":1.02,"descriptions":[{"ISOLanguageCode":"en","name":"SPACER 25,5x35x10","description":"SPACER 25,5x35x10"}]},{"rnum":4,"sku":"0B000004","model":"0B000004","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":2.86,"descriptions":[{"ISOLanguageCode":"en","name":"BUSHING","description":"BUSHING"}]},{"rnum":5,"sku":"0B000007AA","model":"0B000007AA","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":9.3,"descriptions":[{"ISOLanguageCode":"en","name":"Bushing","description":"Bushing"}]},{"rnum":6,"sku":"0B000008","model":"0B000008","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":2.29,"descriptions":[{"ISOLanguageCode":"en","name":"BUSHING","description":"BUSHING"}]},{"rnum":7,"sku":"0B000009","model":"0B000009","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":12.55,"descriptions":[{"ISOLanguageCode":"en","name":"BUSHING","description":"BUSHING"}]},{"rnum":8,"sku":"0B000011","model":"0B000011","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":1.97,"descriptions":[{"ISOLanguageCode":"en","name":"BUSHING","description":"BUSHING"}]},{"rnum":9,"sku":"0B000012","model":"0B000012","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":10.84,"descriptions":[{"ISOLanguageCode":"en","name":"BUSHING","description":"BUSHING"}]},{"rnum":10,"sku":"0B000016AA","model":"0B000016AA","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":1.21,"descriptions":[{"ISOLanguageCode":"en","name":"SPACER 40x45x4,5","description":"SPACER 40x45x4,5"}]},{"rnum":11,"sku":"0B000018","model":"0B000018","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":9.64,"descriptions":[{"ISOLanguageCode":"en","name":"SPACER","description":"SPACER"}]},{"rnum":12,"sku":"0B000019","model":"0B000019","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":3.36,"descriptions":[{"ISOLanguageCode":"en","name":"PLATE","description":"PLATE"}]},{"rnum":13,"sku":"0B000030","model":"0B000030","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":1.6500000000000001,"descriptions":[{"ISOLanguageCode":"en","name":"BUSHING 12x20x14-2x10","description":"BUSHING 12x20x14-2x10"}]},{"rnum":14,"sku":"0B000034","model":"0B000034","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":0.58,"descriptions":[{"ISOLanguageCode":"en","name":"BUSHING 17x20,8x6,3","description":"BUSHING 17x20,8x6,3"}]},{"rnum":15,"sku":"0B000040","model":"0B000040","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":5.5600000000000005,"descriptions":[{"ISOLanguageCode":"en","name":"FLARED WASHER 8,5x42x5","description":"FLARED WASHER 8,5x42x5"}]},{"rnum":16,"sku":"0B000049","model":"0B000049","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":2.48,"descriptions":[{"ISOLanguageCode":"en","name":"SQUARE BUSHING","description":"SQUARE BUSHING"}]},{"rnum":17,"sku":"0B000050AA","model":"0B000050AA","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":4.0600000000000005,"descriptions":[{"ISOLanguageCode":"en","name":"BUSHING","description":"BUSHING"}]},{"rnum":18,"sku":"0B000050AB","model":"0B000050AB","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":3.93,"descriptions":[{"ISOLanguageCode":"en","name":"BUSCHING","description":"BUSCHING"}]},{"rnum":19,"sku":"0B000051","model":"0B000051","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":1.34,"descriptions":[{"ISOLanguageCode":"en","name":"SPACER 10,25x17x16,5","description":"SPACER 10,25x17x16,5"}]},{"rnum":20,"sku":"0B000054","model":"0B000054","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":1.34,"descriptions":[{"ISOLanguageCode":"en","name":"SPACER 10,25x17x27","description":"SPACER 10,25x17x27"}]},{"rnum":21,"sku":"0B000056","model":"0B000056","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":32.77,"descriptions":[{"ISOLanguageCode":"en","name":"BASE FOR ENCODER PIN","description":"BASE FOR ENCODER PIN"}]},{"rnum":22,"sku":"0B000057","model":"0B000057","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":11.85,"descriptions":[{"ISOLanguageCode":"en","name":"SPRING RETAINER","description":"SPRING RETAINER"}]},{"rnum":23,"sku":"0B000060","model":"0B000060","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":15.280000000000001,"descriptions":[{"ISOLanguageCode":"en","name":"SUPPORT for ELECTRONIC","description":"SUPPORT for ELECTRONIC"}]},{"rnum":24,"sku":"0B000062","model":"0B000062","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":2.16,"descriptions":[{"ISOLanguageCode":"en","name":"MAGNET SUPPORT","description":"MAGNET SUPPORT"}]},{"rnum":25,"sku":"0B000064","model":"0B000064","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":2.79,"descriptions":[{"ISOLanguageCode":"en","name":"SPACER 83x44,5","description":"SPACER 83x44,5"}]},{"rnum":26,"sku":"0B000065","model":"0B000065","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":1.72,"descriptions":[{"ISOLanguageCode":"en","name":"SPACER 16,25x32x5","description":"SPACER 16,25x32x5"}]},{"rnum":27,"sku":"0B000073","model":"0B000073","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":2.73,"descriptions":[{"ISOLanguageCode":"en","name":"BUSHING for HANDLEBAR","description":"BUSHING for HANDLEBAR"}]},{"rnum":28,"sku":"0B000078","model":"0B000078","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":6.47,"descriptions":[{"ISOLanguageCode":"en","name":"Spacer","description":"Spacer"}]},{"rnum":29,"sku":"0B000079","model":"0B000079","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":4.19,"descriptions":[{"ISOLanguageCode":"en","name":"BUSHING 16x18x25","description":"BUSHING 16x18x25"}]},{"rnum":30,"sku":"0B000082","model":"0B000082","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":2.86,"descriptions":[{"ISOLanguageCode":"en","name":"BUSHING","description":"BUSHING"}]},{"rnum":31,"sku":"0B000083","model":"0B000083","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":1.34,"descriptions":[{"ISOLanguageCode":"en","name":"Spacer 10.2x14.5x28","description":"Spacer 10.2x14.5x28"}]},{"rnum":32,"sku":"0B000086","model":"0B000086","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":1.4000000000000001,"descriptions":[{"ISOLanguageCode":"en","name":"SPRING SLEEVE","description":"SPRING SLEEVE"}]},{"rnum":33,"sku":"0B000089AA","model":"0B000089AA","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":0.58,"descriptions":[{"ISOLanguageCode":"en","name":"BUSHING","description":"BUSHING"}]},{"rnum":34,"sku":"0B000093","model":"0B000093","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":0.7000000000000001,"descriptions":[{"ISOLanguageCode":"en","name":"SPACER","description":"SPACER"}]},{"rnum":35,"sku":"0B000094","model":"0B000094","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":0.45,"descriptions":[{"ISOLanguageCode":"en","name":"Spacer","description":"Spacer"}]},{"rnum":36,"sku":"0B000095","model":"0B000095","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":12.43,"descriptions":[{"ISOLanguageCode":"en","name":"FLARED WASHER 10,25x35x10","description":"FLARED WASHER 10,25x35x10"}]},{"rnum":37,"sku":"0B000096","model":"0B000096","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":0.58,"descriptions":[{"ISOLanguageCode":"en","name":"SPACER","description":"SPACER"}]},{"rnum":38,"sku":"0B000097","model":"0B000097","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":0.45,"descriptions":[{"ISOLanguageCode":"en","name":"DISPLAY SPACER","description":"DISPLAY SPACER"}]},{"rnum":39,"sku":"0B000104","model":"0B000104","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":2.92,"descriptions":[{"ISOLanguageCode":"en","name":"HAND SENSOR BUSHING","description":"HAND SENSOR BUSHING"}]},{"rnum":40,"sku":"0B000105","model":"0B000105","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":2.98,"descriptions":[{"ISOLanguageCode":"en","name":"BUSHING","description":"BUSHING"}]},{"rnum":41,"sku":"0B000107","model":"0B000107","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":6.09,"descriptions":[{"ISOLanguageCode":"en","name":"BUSHING 25,25x32x43","description":"BUSHING 25,25x32x43"}]},{"rnum":42,"sku":"0B000110","model":"0B000110","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":6.22,"descriptions":[{"ISOLanguageCode":"en","name":"SPACER 10,25x30x10","description":"SPACER 10,25x30x10"}]},{"rnum":43,"sku":"0B000113","model":"0B000113","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":15.21,"descriptions":[{"ISOLanguageCode":"en","name":"WASHER d=38","description":"WASHER d=38"}]},{"rnum":44,"sku":"0B000114","model":"0B000114","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":4.44,"descriptions":[{"ISOLanguageCode":"en","name":"SELF-LUBRICATING BUSHING","description":"SELF-LUBRICATING BUSHING"}]},{"rnum":45,"sku":"0B000124","model":"0B000124","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":3.87,"descriptions":[{"ISOLanguageCode":"en","name":"BUSHING","description":"BUSHING"}]},{"rnum":46,"sku":"0B000130","model":"0B000130","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":5.07,"descriptions":[{"ISOLanguageCode":"en","name":"Spacer 12.5x24x3","description":"Spacer 12.5x24x3"}]},{"rnum":47,"sku":"0B000133","model":"0B000133","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":0.58,"descriptions":[{"ISOLanguageCode":"en","name":"BUSHING 12,5x16x7,5-20x1,5","description":"BUSHING 12,5x16x7,5-20x1,5"}]},{"rnum":48,"sku":"0B000140","model":"0B000140","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":0.58,"descriptions":[{"ISOLanguageCode":"en","name":"BUSHING 14x20x25-9x3","description":"BUSHING 14x20x25-9x3"}]},{"rnum":49,"sku":"0B000162","model":"0B000162","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":0.39,"descriptions":[{"ISOLanguageCode":"en","name":"SPACER","description":"SPACER"}]},{"rnum":50,"sku":"0B000163-GD","model":"0B000163","category":"Other Equipment","subcategory":"Spare Parts","currencyISOCode":"USD","pricelistCode":"ND$","price":3.11,"descriptions":[{"ISOLanguageCode":"en","name":"Spacer","description":"Spacer"}]}]}


It only returns the:

{"totalSize":57599,"nextRecordsUrl":"http://api-qas.technogym.com:8080/V1.0/pricebooks/78f05333be1990966f181bc65c529a67","records":

It seems that those are the only arrays but the rest are RECORDS... How do I get that out?

Thanks

Ruan
Message modifié, 22 février 2017 - 10:27
//hostimage.webdev.info/avatars/default.gif
Posté le 23 février 2017 - 17:15
Hi. This is wirking for me:

sJson_dados is string = fLoadText(fExeDir() + "\json.txt")

vDados_json is Variant = JSONToVariant(sJson_dados)

_m is Variant

FOR EACH _m OF vDados_json.records

//trace(_m..Name,_m..Value)
dados_json_itens(_m)
END


INTERNAL Procedure dados_json_itens(_itens is Variant)
// FOR EACH _m2 OF _itens
// trace(_m2.rnum,_m2.sku,_m2.model,_m2.category,_m2.price)
// END
Trace(_itens.rnum,_itens.sku,_itens.model,_itens.category,_itens.price)
END
//hostimage.webdev.info/avatars/SMNMuGqoaBbhEqRO8r9MMA
Membre enregistré
151 messages
Popularité : +1 (1 vote)
Posté le 24 février 2017 - 08:15
Rubén Sánchez Peña wrote:
Hi. This is wirking for me:

sJson_dados is string = fLoadText(fExeDir() + "\json.txt")

vDados_json is Variant = JSONToVariant(sJson_dados)

_m is Variant

FOR EACH _m OF vDados_json.records

//trace(_m..Name,_m..Value)
dados_json_itens(_m)
END


INTERNAL Procedure dados_json_itens(_itens is Variant)
// FOR EACH _m2 OF _itens
// trace(_m2.rnum,_m2.sku,_m2.model,_m2.category,_m2.price)
// END
Trace(_itens.rnum,_itens.sku,_itens.model,_itens.category,_itens.price)
END


Good Day

You Rubén Sánchez Peña are a machine!!!! Thanks so much this is exactly what I needed.

Thanks so so much.

Ruan
//hostimage.webdev.info/avatars/SMNMuGqoaBbhEqRO8r9MMA
Membre enregistré
151 messages
Popularité : +1 (1 vote)
Posté le 24 février 2017 - 08:32
Rubén Sánchez Peña wrote:
Hi. This is wirking for me:

sJson_dados is string = fLoadText(fExeDir() + "\json.txt")

vDados_json is Variant = JSONToVariant(sJson_dados)

_m is Variant

FOR EACH _m OF vDados_json.records

//trace(_m..Name,_m..Value)
dados_json_itens(_m)
END


INTERNAL Procedure dados_json_itens(_itens is Variant)
// FOR EACH _m2 OF _itens
// trace(_m2.rnum,_m2.sku,_m2.model,_m2.category,_m2.price)
// END
Trace(_itens.rnum,_itens.sku,_itens.model,_itens.category,_itens.price)
END



Sorry I have one last question on this.

I see they do not add the descriptions under the record set but separate under records named: descriptions

records [50]
0 {9}
rnum : 1
sku : 0B000001
model : 0B000001
category : Other Equipment
subcategory : Spare Parts
currencyISOCode : USD
pricelistCode : ND$
price : 7.74

descriptions [1]
0 {3}
ISOLanguageCode : en
name : SPACER 25,5x36x116,5
Description : SPACER 25,5x36x116,5


How would I pull that?

Tried:

FOR EACH _m OF vDados_json.descriptions
END


But no data return

Then tried:

FOR EACH _m OF vDados_json.records.descriptions
dados_json_itens(_m)
END


Returned error

Is there another way?
//hostimage.webdev.info/avatars/default.gif
Posté le 24 février 2017 - 13:20
Hi. The fields descriptions is an array of values andyou must acces it with another Variant variable:

sJson_dados is string = fLoadText(fExeDir() + "\json.txt")

vDados_json is Variant = JSONToVariant(sJson_dados)

_m is Variant

FOR EACH _m OF vDados_json.records

//trace(_m..Name,_m..Value)
dados_json_itens(_m)
END


INTERNAL Procedure dados_json_itens(_itens is Variant)
// FOR EACH _m2 OF _itens
// trace(_m2.rnum,_m2.sku,_m2.model,_m2.category,_m2.price)
// END
vDesc is Variant = _itens.descriptions[1]
Trace(_itens.rnum,_itens.sku,_itens.model,_itens.category,_itens.price,vDesc.description)
END
//hostimage.webdev.info/avatars/SMNMuGqoaBbhEqRO8r9MMA
Membre enregistré
151 messages
Popularité : +1 (1 vote)
Posté le 24 février 2017 - 14:05
Rubén Sánchez Peña wrote:
Hi. The fields descriptions is an array of values andyou must acces it with another Variant variable:

sJson_dados is string = fLoadText(fExeDir() + "\json.txt")

vDados_json is Variant = JSONToVariant(sJson_dados)

_m is Variant

FOR EACH _m OF vDados_json.records

//trace(_m..Name,_m..Value)
dados_json_itens(_m)
END


INTERNAL Procedure dados_json_itens(_itens is Variant)
// FOR EACH _m2 OF _itens
// trace(_m2.rnum,_m2.sku,_m2.model,_m2.category,_m2.price)
// END
vDesc is Variant = _itens.descriptions[1]
Trace(_itens.rnum,_itens.sku,_itens.model,_itens.category,_itens.price,vDesc.description)
END



That is perfect!!!!

Thanks for your assistance on this.

Ruan