EnablingJSONIN: Difference between revisions
From DataFlex Wiki
Jump to navigationJump to search
m Created page with "Here's how to generate there required files for enabling JSON in your webservice. #Know where your project files are. #Grab DBXRay here : ftp://ftp.stureaps.dk/ #Choose the wor..." |
m fix code tags, add category |
||
(3 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
{{underconst}} | |||
Here's how to generate there required files for enabling JSON in your webservice. | Here's how to generate there required files for enabling JSON in your webservice. | ||
Line 9: | Line 12: | ||
Now you can write code like the following: | Now you can write code like the following: | ||
< | <source lang="dataflex"> | ||
... | ... | ||
Line 35: | Line 38: | ||
End | End | ||
End_Procedure | End_Procedure | ||
</ | </source> | ||
oProduct is a traditional webservice using SOAP. | oProduct is a traditional webservice using SOAP. | ||
Line 42: | Line 45: | ||
Now . Given the following structure definitions: | Now . Given the following structure definitions: | ||
< | <source lang="dataflex"> | ||
Struct meta | Struct meta | ||
Boolean success | Boolean success | ||
String msg | String msg | ||
End_Struct | End_Struct | ||
Struct tReview | Struct tReview | ||
Integer id | Integer id | ||
Integer productId | Integer productId | ||
String comment | String comment | ||
String author | String author | ||
End_Struct | End_Struct | ||
Struct tProduct | Struct tProduct | ||
Integer id | Integer id | ||
String name | String name | ||
String company | String company | ||
tReview[] reviews | tReview[] reviews | ||
End_Struct | End_Struct | ||
Struct tAddProductRequest | Struct tAddProductRequest | ||
String token | String token | ||
tProduct product | tProduct product | ||
End_Struct | End_Struct | ||
Struct tGetProductResponse | Struct tGetProductResponse | ||
Meta meta | Meta meta | ||
tProduct product | tProduct product | ||
End_Struct | End_Struct | ||
Struct tRequest | Struct tRequest | ||
String token | String token | ||
Integer identifier | Integer identifier | ||
End_Struct | End_Struct | ||
Struct tResponse | Struct tResponse | ||
Meta meta | Meta meta | ||
Integer id | Integer id | ||
End_Struct | End_Struct | ||
</ | </source> | ||
You will be able to send tAddProductRequest as JSON from the client side as the request parameter | You will be able to send tAddProductRequest as JSON from the client side as the request parameter | ||
To parse the incoming request from ExtJS 4 you could use the following model definition: | |||
<source lang="javascript"> | |||
Ext.regModel('Acme.Product', { | |||
idProperty: 'id', | |||
successProperty: 'meta.success', | |||
fields: [ | |||
{name:'id', type:'int'}, | |||
{name: "name", type:"string"}, | |||
{name: "company", type:"string"} | |||
], | |||
hasMany: {model:'Acme.Review', name: 'reviews', associationKey: 'reviews'} | |||
}); | |||
Ext.regModel('Acme.Review', { | |||
idProperty: 'id', | |||
fields: [ | |||
'id', | |||
'product_id', | |||
'comment', | |||
'author' | |||
], | |||
belongsTo:'Acme.Product' | |||
}); | |||
</source> | |||
[[Category:JSON]] |
Latest revision as of 12:08, 13 August 2019
EnablingJSONIN page under construction
Here's how to generate there required files for enabling JSON in your webservice.
- Know where your project files are.
- Grab DBXRay here : ftp://ftp.stureaps.dk/
- Choose the workspace using workspace selector
- select Functions|Generate Struct Packages for project
Now you can write code like the following:
... Use StructPkg\Struct_tReview.pkg Use StructPkg\Struct_tProduct.pkg Use StructPkg\Struct_tAddProductRequest.pkg Use Product.wo Use Structures.pkg Object oProductJSON is a cWebService ... Procedure CreateProduct String Request tAddProductRequest stRequest tJsonNode stJson If (StringToDoc(oJsonFunctions, &request, &stJson)) Begin Send JsonToStruct of oStructHandler_tAddProductRequest stJson (&stRequest) Function_Return (CreateProduct(oProduct, stRequest)) End Else Begin Error 666 "String parameter does not contain a valid JSON object" End End_Procedure
oProduct is a traditional webservice using SOAP.
Now . Given the following structure definitions:
Struct meta Boolean success String msg End_Struct Struct tReview Integer id Integer productId String comment String author End_Struct Struct tProduct Integer id String name String company tReview[] reviews End_Struct Struct tAddProductRequest String token tProduct product End_Struct Struct tGetProductResponse Meta meta tProduct product End_Struct Struct tRequest String token Integer identifier End_Struct Struct tResponse Meta meta Integer id End_Struct
You will be able to send tAddProductRequest as JSON from the client side as the request parameter
To parse the incoming request from ExtJS 4 you could use the following model definition:
Ext.regModel('Acme.Product', { idProperty: 'id', successProperty: 'meta.success', fields: [ {name:'id', type:'int'}, {name: "name", type:"string"}, {name: "company", type:"string"} ], hasMany: {model:'Acme.Review', name: 'reviews', associationKey: 'reviews'} }); Ext.regModel('Acme.Review', { idProperty: 'id', fields: [ 'id', 'product_id', 'comment', 'author' ], belongsTo:'Acme.Product' });