PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Procedure fro processing the JSON data
  • Page returning the data in JSON format
  • IMPORTANT: Validity of JSON
  • Security
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
JSONExecuteExternal (Function)
In French: JSONExécuteExterne
Warning
From version 22, We recommend that you use JSONExecute. Indeed, the Webservices 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).
As soon as the result is available, JSONExecuteExternal automatically calls a browser procedure used to retrieve this result.
Example
// 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 AWP page
JSONExecuteExternal(...
"http://mysite/mysite_WEB/US/PAGE_Object.awp?id=12", ...
"JsonCallback", FunctionResponse)
// The AWP page expects a parameter named "JsonCallback"
// that will contain the name of the procedure to run in return
Syntax
JSONExecuteExternal(<Page URL> , <Parameter Name> , <Procedure Name>)
<Page URL>: Character string (with quotes)
URL of the page that returns the data in JSON format.
<Parameter Name>: Character string (with quotes)
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 (with or without quotes)
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 Call>)
The parameter passed to this procedure is a dynamic object, containing the JSON data. It must be indicated in the declaration of the procedure.
Remarks

Procedure fro processing the 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 transmitted as 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: &JsonCallback=FunctionResponse in addition
// at the end of the URL to indicate the return function

Page returning the data in JSON format

The page that returns the data in JSON format can be an AWP page, a PHP page or any other type of page.
If this page is a WEBDEV page, this page can be in AWP format or in PHP format. This page must return the data in JSON format with StringDisplay. Furthermore, StringToUTF8 must also be used to get a valid format.
For example, the following code is used to create 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:  [
{lastname: "smith", firstname: "john"},
{lastname: "doe", firstname: "mary"},
{lastname: "martin", firstname: "laura"}]
} );
]

// 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 ot the JSON object
// with the name of the javascipt procedure to call
StringDisplay(StringToUTF8(sObject))

IMPORTANT: Validity of JSON

No check is performed regarding the validity of JSON received from the server. Make sure that the page called in a trusted page to avoid having a JavaScript injection in the current page.

Security

To increase the security of the transmitted data, you have the ability to use a secure page (https).
Components
WEBDEV - Browser code WDJS.DLL
Minimum required version
  • Version 14
Comments
Click [Add] to post a comment