ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Standard functions / String functions
  • Encoding
  • Content of variant
  • Checking if a value is NULL
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Converts a JSON string to a Variant variable.
sJZon is ANSI string = [
{
"glossary": {
"title": "example glossary",
"GlossDiv": {
"title": "S",
"GlossList": {
"GlossEntry": {
"ID": "SGML",
"SortAs": "SGML",
"GlossTerm": "Standard Generalized Markup Language",
"Acronym": "SGML",
"Abbrev": "ISO 8879:1986",
"GlossDef": {
"para": "A meta-markup language, used to create markup languages such as DocBook.",
"GlossSeeAlso": ["GML", "XML"]
},
"GlossSee": "markup"
}
}
}
}
}
]
 
let jz = JSONToVariant(sJZon)
Syntax
<Result> = JSONToVariant(<JSON data>)
<Result>: Variant
Name of Variant variable containing the conversion result.
<JSON data>: ANSI character string encoded in 7-bit ASCII + JSON or UTF-8 encoding
Character string containing the data in JSON format.
Remarks

Encoding

The encoding used corresponds to the JSON standard:
  • 7-bit ASCII encoding for the first 128 characters, i.e., unaccented characters
  • JSON encoding for the other characters: "\u" followed by the character code in 4-byte hexadecimal format. Example: for the "é" character (ASCII code 233, hexadecimal code E9), the encoding corresponds to "\u00E9".

Content of variant

The content of the variant depends on the JSON used. It can correspond to:
  • the Null value
  • a simple type: integer, string, boolean, etc.
  • an array
  • a complex object (VariantMember type, corresponding to an array of members where each member is a variant).

Checking if a value is NULL

The "NULL" value is often used in JSON.
To check the "NULL" value of a variant, you can:
  • use the Value property of the variant. For example:
    v is Variant = JSONToVariant("{""m"":null}")
    IF v.m..Value = Null THEN Trace("NULL")
  • check the NULL value directly. For example:
    v is Variant = JSONToVariant("{""m"":null}")
    IF v.m = Null THEN Trace("NULL")
Component: wd290xml.dll
Minimum version required
  • Version 19
This page is also available for…
Comments
Navegar nos dados de um json
js is JSON
FOR i = 1 _TO_ js..Member..Count
js..Member[i]..Name
END
Boller
23 Oct. 2023
exemplo jsontovariant
https://windevdesenvolvimento.blogspot.com/2021/05/dicas-3325-windev-webdev-mobile.html
https://youtu.be/MQ7SrcjV33E
EDT_retorno=""
S_url is string="https://economia.awesomeapi.com.br/json/last/USD-BRL"
IF HTTPRequest(S_url) THEN
EDT_retorno=UTF8ToAnsi(HTTPGetResult())
let json_dados=JSONToVariant(EDT_retorno)
FOR EACH json_linha OF json_dados..Member
FOR EACH json_linha_Detalhe OF json_linha
IF json_linha_Detalhe..Name="high" THEN
EDT_dolar=json_linha_Detalhe..Value
END
END
END
END
amarildo
11 May 2021
Video Json
bom dia
https://youtu.be/WkltQUt_Bak
https://windevdesenvolvimento.blogspot.com/2019/07/dicas-2204-windev-webdev-mobile-json-6.html
// Youtube Amarildo Matos
s_json_dados is string=fLoadText(EDT_ARQUIVO_JSON)
//ESSA LINHA DIFERENTE
let variavel_json=JSONToVariant(s_json_dados)
//ESSA LINHA DIFERENTE
TableDeleteAll(TABLE_JSON)
FOR nNCONTADOR=1 TO variavel_json..Count
nNOCORRENCIA is int=TableAddLine(TABLE_JSON)
TABLE_JSON[nNOCORRENCIA].COL_SHORT_DESCRIPTION=variavel_json[nNCONTADOR].short_description
TABLE_JSON[nNOCORRENCIA].COL_PRICE=variavel_json[nNCONTADOR].price
TABLE_JSON[nNOCORRENCIA].COL_STOCK_QUANTITY=variavel_json[nNCONTADOR].stock_quantity
END

amarildo
18 Jul. 2019
Video JSONToVariant
https://youtu.be/ZC3G1PrDN9g

https://windevdesenvolvimento.blogspot.com/2019/05/dicas-2107-windev-webdev-mobile-json-4.html

// BTN_LER_SJON
TableDeleteAll(TABLE_CLIENTE)
vTeste is Variant
vTeste=JSONToVariant(EDT_retorno)
FOR EACH indice OF vTeste
TableAddLine(TABLE_CLIENTE,indice.clienteid,indice.nome)
END

amarildo
13 May 2019

Last update: 05/26/2022

Send a report | Local help