AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / WLanguage / Funciones WLanguage / Funciones específicas de la Web / Funciones varias de WEBDEV
  • Procedure for processing JSON data
  • Page that returns JSON data
  • IMPORTANT: JSON validity
  • Security
WINDEV
WindowsLinuxJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac Catalyst
Otros
Procedimientos almacenados
Advertencia
A partir de la versión 22, It is recommended to use JSONExecute. Indeed, the web services returning data in JSON format are now using the CORS protocol to simplify the security.
Calls an external server URL that returns data in JSON format (JavaScript Object Notation). The server data is evaluated and transmitted to the callback function in object format.
This function is not locking. The other processes continue to run (no matter whether the data is retrieved or not).
Once the result is available, JSONExecuteExternal automatically calls a browser procedure to retrieve the result.
Ejemplo
// Run a JSON service on Google
// Google expects the name of the procedure that will process the JSON object 
// in the parameter named "callback"
// and in this case, the procedure that will process the object is named "GoogleCalendar"
JSONExecuteExternal(...
	"http://www.google.com/calendar/feeds/mysite@gmail.com" + ...
	"/public/full?alt=json-in-script&orderby=starttime&max-results=15&" + ...
	"singleevents=true&sortorder=ascending&futureevents=true", ...
	 "&callback"=GoogleCalendar)

// This will generate a URL for calling the json function:
// http://www.google.com/calendar/feeds/mysite@gmail.com/public/full?alt
// =json-in-script&orderby=starttime&max-results=15&singleevents=true&
// sortorder=ascending&futureevents=true&callback=GoogleCalendar
// Run a JSON service on an Active WEBDEV Page
JSONExecuteExternal(...
	"http://mysite/mysite_WEB/US/PAGE_Object.awp?id=12", ...
	"JsonCallback", FunctionResponse)
// The Active WEBDEV Page expects a parameter named "JsonCallback" 
// that will contain the name of the procedure to run in return
Sintaxis
JSONExecuteExternal(<Page URL> , <Parameter name> , <Procedure name>)
<Page URL>: Character string
URL of the page that returns the JSON data.
<Parameter name>: Character string
Name of the parameter added to the URL by WEBDEV to indicate the name of the procedure for processing the JSON data to the relevant server. The name of this parameter depends on the documentation of the JSON function called, it is "callback" in most cases.
<Procedure name>: Character string
Name of the browser procedure (global or local procedure) that performs the process of the JSON data.
This procedure has the following format:
PROCEDURE <Browser procedure> (<JSON result of the call>)
The parameter passed to this procedure is a dynamic object that contains the JSON data. It must be indicated in the declaration of the procedure.
Observaciones

Procedure for processing JSON data

The JSON result must be returned as a JSON code enclosed in a call to the procedure used to process this data.
The name of this procedure is directly passed as a parameter in the URL for calling the page. The name of this parameter is specified in JSONExecuteExternal.
For example:
JSONExecuteExternal("http://MySite/MySite_WEB/US/PAGE_Object.awp?id=12", ...
	"JsonCallback", FunctionResponse)
will be used to build the following URL:
"http://MySite/MySite_WEB/FR/PAGE_Object.awp?id=12&JsonCallback=FunctionResponse"
// WEBDEV added: &amp;JsonCallback=ReponseFunction as well 
// at the end of the URL to indicate the return function

Page that returns JSON data

The page that returns the data in JSON format can be an Active WEBDEV Page, a PHP page or any other type of page.
If it is a WEBDEV page, it can be an Active WEBDEV Page or a PHP page. This page must return the JSON data with StringDisplay. Furthermore, StringToUTF8 must also be used to get a valid format.
For example, the following code creates the string that will be returned. This string contains the code used to define an object and an array. The code used is JavaScript code.
PageParameter is used to process an external call. In this case, the JSON data returned is formatted with the name of the process procedure.
// String containing a JSON object
sObject is string = [
	%1 ( {id: 12,
	list: [
		{ last name: "smith", first name: "john"},
		{ last name: "dupond", first name: "marie"},
		{name: "martin", first name: "lauré"}]
} );
]

// Add the name of the callback procedure (instead of %1)
// This name is expected in a parameter named "JsonCallback"
sObject = StringBuild(sObject, PageParameter("JsonCallback"))

// Returns the string of the JSON object 
// with the name of the javascipt procedure to call
StringDisplay(StringToUTF8(sObject))

IMPORTANT: JSON validity

The validity of the JSON data received from the server is not checked. Make sure that the called page is a trusted page to prevent JavaScript injection attacks in the current page.

Security

To protect data, you can use a secure page (https URL).
Componente: WDJS.DLL
Versión mínima requerida
  • Versión 14
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 14/05/2025

Señalar un error o enviar una sugerencia | Ayuda local