Created
September 15, 2013 19:31
-
-
Save fushnisoft/6573705 to your computer and use it in GitHub Desktop.
Example of implementing a really, really basic DLLExport of Newtonsoft.Json reader and writer in Clarion. But it works pretty darn well! http://james.newtonking.com/projects/json/help/html/ReadingWritingJSON.htm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| GetJsonData PROCEDURE(LONG pDate) | |
| Json JsonClassType | |
| CODE | |
| Json.Init() | |
| Json.InitWriter() | |
| Json.WriteStartObject() | |
| Json.WritePropertyName('key') | |
| Json.WriteValue('ASDR-WERT-DFGG-RRTY') | |
| Json.WritePropertyName('bufferTime') | |
| Json.WriteValue('300') | |
| Json.WritePropertyName('vehicles') | |
| Json.WriteStartArray() | |
| Clear(JOU:Record) | |
| JOU:Date_Date_DATE = pDate | |
| Set(JOU:FK_Journeys_Dateline, JOU:FK_Journeys_Dateline) | |
| LOOP UNTIL Access:Journeys.Next() <> Level:Benign OR JOU:Date_Date_DATE <> pDate | |
| VEH:Rego = JOU:Vehicle | |
| IF Access:Vehicle.Fetch(VEH:K_Rego) <> Level:Benign | |
| CYCLE | |
| END | |
| Json.WriteStartObject() | |
| Json.WritePropertyName('rego') | |
| Json.WriteValue(VEH:Rego) | |
| Json.WritePropertyName('location') | |
| Json.WriteValue('some location') | |
| Json.WritePropertyName('seats') | |
| Json.WriteValue(VEH:Seats ) | |
| Json.WritePropertyName, 'costPerKm') | |
| Json.WriteValue(VEH:CostPerKm) | |
| Json.WriteEnd() | |
| END | |
| Json.WriteEndArray() | |
| Json.WriteEndObject() | |
| RETURN Json.ToJson() | |
| --------- | |
| The return will look something like this: | |
| { | |
| "key": "ASDR-WERT-DFGG-RRTY!", | |
| "bufferTime": "300", | |
| "vehicles": [ | |
| { | |
| "rego": "CT2345", | |
| "location": "some location", | |
| "seats": "4", | |
| "costPerKm": "0.42" | |
| }, | |
| { | |
| "rego": "ABC-123", | |
| "location": "some location", | |
| "seats": "0", | |
| "costPerKm": "0" | |
| }, | |
| { | |
| "rego": "XXYY", | |
| "location": "some location", | |
| "seats": "0", | |
| "costPerKm": "0" | |
| } | |
| ] | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment