Jump to content

Search the Community

Showing results for tags 'json'.

  • Search By Tags

    Type tags separated by commas.
  • Search By Author

Content Type


Forums

  • uniGUI Public
    • Announcements
    • General
    • Feature Requests
    • Installation
    • Deployment
    • Other Platforms
  • Licensing
    • Licensing
    • Ordering uniGUI
  • Bug Reports
    • Active Reports
    • Closed Reports
    • Old Bug Reports
  • uniGUI Development
    • General Development
    • uniGUI Releases & Roadmaps
    • Utilities
  • Mobile Platform
    • uniGUI Mobile
    • Mobile Browsers
  • Users Area
    • Sample Projects
    • Components and Code Samples
    • Third Party Components
  • Non-English
    • Non-English
  • Miscellaneous
    • Hosting
    • Server Security
    • Jobs

Find results in...

Find results that contain...


Date Created

  • Start

    End


Last Updated

  • Start

    End


Filter by number of...

Joined

  • Start

    End


Group


AIM


MSN


Website URL


ICQ


Yahoo


Jabber


Skype


Location


Interests

Found 6 results

  1. This post explains how to parse a master/detail JSON object in Delphi for those interested. It is an addendum to a post I added to the following thread about REST API: http://forums.unigui.com/index.php?/topic/23222-using-unigui-rest-full-server/#comment-136637 I use here as an example an invoice object in JSON format received via an http POST request. The procedure below parses the the JSON object and stores the invoice field values in a Stringlist for further processing Assuming the object we have received looks like this (1 invoice header and 3 invoice details): // {"invNo":"0001234", "invDate":"2023-06-21","customer":"Robert Smith", "invAmt":271.50, // "invDetails" :[{"seqNo":1, "productCode":"SPRINGS","description":"Galv 2.0m Tensile", "qty":2, "price":120.50}, // {"seqNo":2, "productCode":"LUB","description":"2cm Light Grease", "qty":1, "price":20.50}, // {"seqNo":3, "productCode":"FREIGHT","description":"Freiht Cost", "qty":1, "price":10.00}] // } //Some JSON Helper functions we'll use (Delphi unit required : System.JSON) function getJsonCurrency(wObj: TJSONObject; wItem: String): Currency; var aObjItem : TJSONString; begin aObjItem := wObj.Get(wItem).JsonValue as TJSONString; Result := StrToFloat(aObjItem.Value); end; function getJsonDate(wObj: TJSONObject; wItem: String; fmt : TFormatSettings): Currency; var aObjItem : TJSONString; aValue : String; begin aObjItem := wObj.Get(wItem).JsonValue as TJSONString; aValue := aObjItem.Value; Result := StrToDate(aValue, fmt); end; function getJsonInteger(wObj: TJSONObject; wItem: String): Integer; var aObjItem : TJSONString; begin aObjItem := wObj.Get(wItem).JsonValue as TJSONString; Result := StrToInt(aObjItem.Value); end; function getJsonString(wObj: TJSONObject; wItem: String): String; var aObjItem : TJSONString; begin aObjItem := wObj.Get(wItem).JsonValue as TJSONString; Result := aObjItem.Value; end; //-- //Parsing the object procedure ProcessJSONInvoice(wJSONInvoice: String); type //Invoice Header Structure TInvoiceHeader = Record InvNo : String; Customer : String; InvDate : TDateTime; InvAmt : Currency; end; //Invoice Detail Structure TInvoiceDetail = Record LineSeq : Integer; ItemCode : String; Description : String; Qty : Currency; Price : Currency; end; var aJSONObj : TJSONObject; aDetailsArray : TJSONArray; InvoiceHeader : TInvoiceHeader; InvoiceDetail : TInvoiceDetail; aInvoiceData, aDataItems : TStringList; i : Integer; dateFmt : TFormatSettings; begin aInvoiceData := TStringList.Create; aDataItems := TStringList.Create; aJSONObj := TJSONObject.ParseJSONValue(wJSONInvoice) as TJSONObject; try //Our Date Format dateFmt := TFormatSettings.Create(LOCALE_USER_DEFAULT); dateFmt.ShortDateFormat := 'yyyy/mm/dd'; dateFmt.DateSeparator := '-'; //Extract Invoice Header with InvoiceHeader do begin InvNo := getJsonString(aJSONObj, 'invNo'); InvDate := getJsonDate(aJSONObj, 'invDate', dateFmt); Customer := getJsonString(aJSONObj, 'customer'); InvAmt := getJsonCurrency(aJSONObj, 'invAmt'); //Add to StringList aDataItems.Clear; aDataItems.Add('Header'); aDataItems.Add(InvNo); aDataItems.Add(DateToStr(InvDate)); aDataItems.Add(Customer); aDataItems.Add(FloatToStr(InvAmt)); aInvoiceData.Add(aDataItems.CommaText); end; //Extract Invoice Details aDetailsArray := aJSONObj.Get('invDetails').JsonValue as TJSONArray; for i := 0 to aDetailsArray.Count - 1 do begin aJSONObj := aDetailsArray.Items[i] as TJSONObject; with InvoiceDetail do begin LineSeq := getJsonInteger(aJSONObj, 'seqNo');; ItemCode := getJsonString(aJSONObj, 'productCode'); Description := getJsonString(aJSONObj, 'description');; Qty := getJsonCurrency(aJSONObj, 'qty'); Price := getJsonCurrency(aJSONObj, 'price');; //Add Invoice Details to StringList aDataItems.Clear; aDataItems.Add('Detail'); aDataItems.Add(IntToStr(LineSeq)); aDataItems.Add(ItemCode); aDataItems.Add(Description); aDataItems.Add(FloatToStr(Qty)); aDataItems.Add(FloatToStr(Price)); aInvoiceData.Add(aDataItems.CommaText); end; end; //Forward the stringlist for DB processing; // ProcessInvoice(aInvoiceData); finally aJSONObj.Free; aInvoiceData.Free; aDataItems.Free; end; end;
  2. Example for consumption of Geolocation API enabling complete data collection from a given ip. Get you free API Key at http://ipstack.com/ (free untill 10.000/day ) Project available at https://www.uniguiexpress.com
  3. I have created the following store at runtime, how do I assign this store to my grid ? UniSession.AddJS(grdUsers00.JSName + '.store = "Grid1Store"; '); does nothing ? MyScript:= 'var Grid1Store = new Ext.data.JsonStore( ' + '{ ' + ' root: "users", ' + ' fields: ["id", "name", "email"], ' + ' autoLoad: true, ' + ' data: ' + ' { ' + ' users: [ ' + ' { "id": 1, "name":"John Smith", "email":"jsmith@example.com"}, ' + ' { "id": 2, "name":"Anna Smith", "email":"asmith@example.com"}, ' + ' { "id": 3, "name":"Peter Smith", "email":"psmith@example.com"}, ' + ' { "id": 4, "name":"Tom Smith", "email":"tsmith@example.com"}, ' + ' { "id": 5, "name":"Andy Smith", "email":"asmith@example.com"}, ' + ' { "id": 6, "name":"Nick Smith", "email":"nsmith@example.com"} ' + ' ] ' + ' } ' + '}); '+ 'Grid1Store.load(); '; UniSession.AddJS(MyScript);
  4. Dear all, We are developing UNIGUI mobile web application with online banking transfer. We need to send an encrypted and signed JSON request to the BANK server. Obviously the bank has very tight security protocol need to follow. They only allowed the JSON request coming from registered IP , which is our unigui server site. We already did testing the json request and receive successfully from the server site use normal desktop application. It's involved PGP encryption, json, and HTTP requests component. My problem is because our user use mobile to access the unigui and need to send JSON requests to the bank server. Can you give me advise and guide how do we accomplish that with UNIGUI infrastructure? Really appreciated all the help and clue. Thank you Devya
  5. Hello, Can anyone help me? I have a simple application with a login and a main menu form, very usually, but with a particular parameters in the URL, I need to provide a simple, unformatted text content to the respective user's web browser (that text can be a JSon, XML, OData, etc). This URL contains authentication parameters (something like "127.0.0.1:8077/?authkey=700UB7BN3FM1ZMN"). I need to use the "UniGUIMainModuleBeforeLogin" event of the "UniMainModule", to validate this authentication key, determine which user is accessing the data and only if that key/user is validated, select their respective data and generate the plain text in the format that need. What I need is simple: When this URL with parameters are acessed, after the validation on the "UniGUIMainModuleBeforeLogin" event, instead of showing the Main Menu screen, I need that this simple text (which can be a text in the OData, JSon, XML, etc.) return that plain string back to the user's web browser. Attached is an image that shows what I need. My UniGUI version is "FMSoft uniGUI Complete Professional 1.0.0.1423". I have tried the following approach: procedure TUniMainModule.UniGUIMainModuleBeforeLogin(Sender: TObject; var Handled: Boolean); var xAuthKey, xUserInfo, xStrData : string; begin Handled := False; //Try to get authentication info xAuthKey := (Sender as TUniGUISession).UniApplication.Parameters.Values['odata']; if not xAuthKey.IsEmpty then begin //Validate authentication info and gets the user info xUserInfo := GetUserInfo(xAuthKey); if not xUserInfo.IsEmpty then begin //GetStrData returns information of database based on user info //It can be a JSon, a XML or OData, or even, a simple text xStrData := GetStrData(xUserInfo); { Down here i got troubles } TUniGuiSession(Sender).AResponse.ContentType := 'text/plain'; //tried: 'text/plain', 'text/xml', 'application/json', and others TUniGuiSession(Sender).AResponse.ContentText := xStrData; TUniGuiSession(Sender).AResponse.WriteContent; { Up here i got troubles } //Don't show de login form Handled := True; end; end; end; I tried other approach too, but still nothing: procedure TUniMainModule.UniGUIMainModuleBeforeLogin(Sender: TObject; var Handled: Boolean); var xAuthKey, xUserInfo, xStrData : string; begin Handled := False; //Try to get authentication info xAuthKey := (Sender as TUniGUISession).UniApplication.Parameters.Values['odata']; if not xAuthKey.IsEmpty then begin //Validate authentication info and gets de user info xUserInfo := GetUserInfo(xAuthKey); if not xUserInfo.IsEmpty then begin //GetStrData returns information of database based on user data //It can be a JSon, a XML or OData, or even, a simple text xStrData := GetStrData(xUserInfo); { Down here i got troubles } //Here I got a ajax erro message dialog, with the content of xStrData (Even with the ExecCode param True) TUniGuiSession(Sender).SendResponse(xStrData, False); { Up here i got troubles } //Don't show de login form Handled := True; end; end; end; It must be something simple, but I can not do it. I searched a lot in the forums and did not find anything like what I want to do. Thank you in advance.
  6. Dear, I consult them, I need to make my application unigui, talk to another remote php application, what should I do? I understand using a webservice / XML / JSON, another. I will appreciate your support and feedback as could do this task.
×
×
  • Create New...