fcl-json: what changed
Revision 2 to 3. Removed lines have a minus sign; added lines have a plus sign.
| Old | New | Line | |
|---|---|---|---|
| 1 | 1 | # General info | |
| 2 | 2 | ||
| 3 | - | ||
| 4 | - | ||
| 5 | - | ||
| 3 | + | fcl-json is a [[JSON]] implementation. | |
| 6 | 4 | ||
| 7 | - | ||
| 8 | - | ||
| 9 | - | ||
| 10 | - | ||
| 5 | + | It contains units such as: | |
| 11 | 6 | ||
| 12 | - | ||
| 7 | + | * fpjson: base unit which implements TJsonData and its children, e.g. TJsonObject | |
| 8 | + | * jsonParser: implements TJsonParser, used in the From JsonViewer example below | |
| 9 | + | * jsonConf: implements TJsonConfig which is handy to read/write application data from/to files | |
| 10 | + | * jsonScanner: json source lexical analyzer | |
| 13 | 11 | ||
| 14 | - | ||
| 12 | + | Note: In fpjson, accessing e.g. | |
| 13 | + | ``` | |
| 15 | 14 | SomeJSONObject.Integers['price'] | |
| 16 | 15 | ``` | |
| 17 | 16 | ||
| 18 | - | ||
| 17 | + | may give a SIGSEGV/Access Violation if that integer variable does not exist. This is apparently intentional, see [[1]](<http://bugs.freepascal.org/view.php?id=22273>). You'd have to use the Find method (available since FPC 2.6.2) to first check if the element ('price' in this example) exists. | |
| 19 | 18 | ||
| 20 | 19 | # Streaming | |
| 21 | 20 | ||
| 22 | - | ||
| 21 | + | fcl-json contains the unit "fpjsonrtti" which is used to load objects (TObject instances) from or save them to JSON format. | |
| 23 | 22 | ||
| 24 | - | ||
| 23 | + | See [[Streaming JSON]] for a short example. | |
| 25 | 24 | ||
| 26 | 25 | # Examples | |
| 27 | 26 | ||
| 28 | 27 | ## Getting Started | |
| 29 | - | ||
| 30 | - | ||
| 28 | + | ``` | |
| 31 | 29 | uses | |
| 32 | - | ||
| 33 | - | ||
| 34 | - | ||
| 35 | - | ||
| 36 | - | ||
| 37 | - | ||
| 38 | - | ||
| 39 | - | ||
| 40 | - | ||
| 41 | - | ||
| 42 | - | ||
| 43 | - | ||
| 44 | - | ||
| 45 | - | ||
| 46 | - | ||
| 47 | - | ||
| 48 | - | ||
| 49 | - | ||
| 50 | - | ||
| 51 | - | ||
| 52 | - | ||
| 53 | - | ||
| 54 | - | ||
| 55 | - | ||
| 56 | - | ||
| 57 | - | ||
| 58 | - | ||
| 59 | - | ||
| 60 | - | ||
| 61 | - | ||
| 62 | - | ||
| 63 | - | ||
| 64 | - | ||
| 65 | - | ||
| 66 | - | ||
| 67 | - | ||
| 68 | - | ||
| 69 | - | ||
| 70 | - | ||
| 71 | - | ||
| 72 | - | ||
| 73 | - | ||
| 74 | - | ||
| 75 | - | ||
| 30 | + | fpjson, jsonparser; | |
| 31 | + | ||
| 32 | + | procedure JSONTest; | |
| 33 | + | var | |
| 34 | + | jData : TJSONData; | |
| 35 | + | jObject : TJSONObject; | |
| 36 | + | jArray : TJSONArray; | |
| 37 | + | s : String; | |
| 38 | + | begin | |
| 39 | + | // this is only a minimal sampling of what can be done with this API | |
| 40 | + | ||
| 41 | + | // create from string | |
| 42 | + | jData := GetJSON('{"Fld1" : "Hello", "Fld2" : 42, "Colors" : ["Red", "Green", "Blue"]}'); | |
| 43 | + | ||
| 44 | + | // output as a flat string | |
| 45 | + | s := jData.AsJSON; | |
| 46 | + | ||
| 47 | + | // output as nicely formatted JSON | |
| 48 | + | s := jData.FormatJSON; | |
| 49 | + | ||
| 50 | + | // cast as TJSONObject to make access easier | |
| 51 | + | jObject := jData as TJSONObject; | |
| 52 | + | ||
| 53 | + | // retrieve value of Fld1 | |
| 54 | + | s := jObject.Get('Fld1'); | |
| 55 | + | ||
| 56 | + | // change value of Fld2 | |
| 57 | + | jObject.Integers['Fld2'] := 123; | |
| 58 | + | ||
| 59 | + | // retrieve the second color | |
| 60 | + | s := jData.FindPath('Colors[1]').AsString; | |
| 61 | + | ||
| 62 | + | // add a new element | |
| 63 | + | jObject.Add('Happy', True); | |
| 64 | + | ||
| 65 | + | // add a new sub-array | |
| 66 | + | jArray := TJSONArray.Create; | |
| 67 | + | jArray.Add('North'); | |
| 68 | + | jArray.Add('South'); | |
| 69 | + | jArray.Add('East'); | |
| 70 | + | jArray.Add('West'); | |
| 71 | + | jObject.Add('Directions', jArray); | |
| 72 | + | ||
| 73 | + | end; | |
| 76 | 74 | ``` | |
| 77 | 75 | ||
| 78 | - | ||
| 76 | + | Note: it's necessary to free jData when you have finished with it. Otherwise a memory leak is created. | |
| 79 | 77 | ||
| 80 | 78 | ## Traversing Items | |
| 81 | - | ||
| 82 | - | ||
| 79 | + | ``` | |
| 83 | 80 | uses | |
| 84 | - | ||
| 85 | - | ||
| 86 | - | ||
| 87 | - | ||
| 88 | - | ||
| 89 | - | ||
| 90 | - | ||
| 91 | - | ||
| 92 | - | ||
| 93 | - | ||
| 94 | - | ||
| 95 | - | ||
| 96 | - | ||
| 97 | - | ||
| 98 | - | ||
| 99 | - | ||
| 100 | - | ||
| 101 | - | ||
| 102 | - | ||
| 103 | - | ||
| 104 | - | ||
| 105 | - | ||
| 81 | + | Classes, TypInfo, fpjson, jsonparser; | |
| 82 | + | ||
| 83 | + | procedure JSONItems(Info: TStrings); | |
| 84 | + | var | |
| 85 | + | jData : TJSONData; | |
| 86 | + | jItem : TJSONData; | |
| 87 | + | i, j: Integer; | |
| 88 | + | object_name, field_name, field_value, object_type, object_items: String; | |
| 106 | 89 | begin | |
| 107 | - | ||
| 108 | - | ||
| 109 | - | ||
| 110 | - | ||
| 90 | + | jData := GetJSON('{"A":{"field1":0, "field2": false},"B":{"field1":0, "field2": false}}'); | |
| 91 | + | ||
| 92 | + | for i := 0 to jData.Count - 1 do | |
| 93 | + | begin | |
| 94 | + | jItem := jData.Items[i]; | |
| 95 | + | ||
| 96 | + | object_type := GetEnumName(TypeInfo(TJSONtype), Ord(jItem.JSONType)); | |
| 97 | + | object_name := TJSONObject(jData).Names[i]; | |
| 98 | + | WriteStr(object_items, jItem.Count); | |
| 99 | + | ||
| 100 | + | Info.Append('object type: ' + object_type + '|object name: ' + object_name + '|number of fields: ' + object_items); | |
| 101 | + | ||
| 102 | + | for j := 0 to jItem.Count - 1 do | |
| 103 | + | begin | |
| 104 | + | field_name := TJSONObject(jItem).Names[j]; | |
| 105 | + | field_value := jItem.FindPath(TJSONObject(jItem).Names[j]).AsString; | |
| 106 | + | ||
| 107 | + | Info.Append(field_name + '|' + field_value); | |
| 108 | + | end; | |
| 109 | + | end; | |
| 110 | + | ||
| 111 | + | jData.Free; | |
| 111 | 112 | end; | |
| 112 | - | ||
| 113 | - | ||
| 114 | - | ||
| 115 | - | ||
| 116 | 113 | ``` | |
| 117 | 114 | ||
| 118 | 115 | ## Save/load form position to/from file | |
| 119 | - | ||
| 120 | - | ||
| 116 | + | ``` | |
| 121 | 117 | uses | |
| 122 | - | ||
| 123 | - | ||
| 124 | - | ||
| 125 | - | ||
| 126 | - | ||
| 127 | - | ||
| 128 | - | ||
| 129 | - | ||
| 130 | - | ||
| 131 | - | ||
| 132 | - | ||
| 133 | - | ||
| 134 | - | ||
| 135 | - | ||
| 136 | - | ||
| 137 | - | ||
| 138 | - | ||
| 139 | - | ||
| 118 | + | jsonConf; | |
| 119 | + | ||
| 120 | + | procedure SaveFormPos(AForm: TForm; const AFilename: string); | |
| 121 | + | var | |
| 122 | + | c: TJSONConfig; | |
| 140 | 123 | begin | |
| 141 | - | ||
| 142 | - | ||
| 143 | - | ||
| 144 | - | ||
| 124 | + | c:= TJSONConfig.Create(Nil); | |
| 125 | + | try | |
| 126 | + | //try/except to handle broken json file | |
| 127 | + | try | |
| 128 | + | c.Formatted:= true; | |
| 129 | + | c.Filename:= AFilename; | |
| 130 | + | except | |
| 131 | + | exit; | |
| 132 | + | end; | |
| 133 | + | ||
| 134 | + | c.SetValue('/dialog/max', AForm.WindowState=wsMaximized); | |
| 135 | + | if AForm.WindowState<>wsMaximized then | |
| 136 | + | begin | |
| 137 | + | c.SetValue('/dialog/posx', AForm.Left); | |
| 138 | + | c.SetValue('/dialog/posy', AForm.Top); | |
| 139 | + | c.SetValue('/dialog/sizex', AForm.Width); | |
| 140 | + | c.SetValue('/dialog/sizey', AForm.Height); | |
| 141 | + | end; | |
| 142 | + | finally | |
| 143 | + | c.Free; | |
| 144 | + | end; | |
| 145 | 145 | end; | |
| 146 | - | ||
| 147 | - | ||
| 148 | - | ||
| 149 | - | ||
| 150 | - | ||
| 151 | - | ||
| 152 | - | ||
| 153 | - | ||
| 154 | - | ||
| 155 | - | ||
| 156 | - | ||
| 157 | - | ||
| 158 | - | ||
| 159 | - | ||
| 160 | - | ||
| 161 | - | ||
| 162 | - | ||
| 163 | - | ||
| 146 | + | ||
| 147 | + | procedure LoadFormPos(AForm: TForm; const AFilename: string); | |
| 148 | + | var | |
| 149 | + | nLeft, nTop, nW, nH: Integer; | |
| 150 | + | c: TJSONConfig; | |
| 151 | + | begin | |
| 152 | + | c:= TJSONConfig.Create(Nil); | |
| 153 | + | try | |
| 154 | + | //try/except to handle broken json file | |
| 155 | + | try | |
| 156 | + | c.Formatted:= true; | |
| 157 | + | c.Filename:= AFilename; | |
| 158 | + | except | |
| 159 | + | exit; | |
| 160 | + | end; | |
| 161 | + | ||
| 162 | + | nLeft:= c.GetValue('/dialog/posx', AForm.Left); | |
| 163 | + | nTop:= c.GetValue('/dialog/posy', AForm.Top); | |
| 164 | + | nW:= c.GetValue('/dialog/sizex', AForm.Width); | |
| 165 | + | nH:= c.GetValue('/dialog/sizey', AForm.Height); | |
| 166 | + | AForm.SetBounds(nLeft, nTop, nW, nH); | |
| 167 | + | ||
| 168 | + | if c.GetValue('/dialog/max', false) then | |
| 169 | + | AForm.WindowState:= wsMaximized; | |
| 170 | + | finally | |
| 171 | + | c.Free; | |
| 172 | + | end; | |
| 164 | 173 | end; | |
| 165 | - | ||
| 166 | - | ||
| 167 | - | ||
| 168 | - | ||
| 169 | - | ||
| 170 | - | ||
| 171 | - | ||
| 172 | - | ||
| 173 | - | ||
| 174 | - | ||
| 175 | - | ||
| 176 | - | ||
| 177 | - | ||
| 178 | 174 | ``` | |
| 179 | 175 | ||
| 180 | 176 | ## Save/load TStringList | |
| 181 | - | ||
| 182 | - | ||
| 177 | + | ``` | |
| 183 | 178 | uses | |
| 184 | - | ||
| 185 | - | ||
| 186 | - | ||
| 187 | - | ||
| 188 | - | ||
| 189 | - | ||
| 190 | - | ||
| 191 | - | ||
| 192 | - | ||
| 193 | - | ||
| 194 | - | ||
| 195 | - | ||
| 196 | - | ||
| 197 | - | ||
| 198 | - | ||
| 199 | - | ||
| 200 | - | ||
| 201 | - | ||
| 202 | - | ||
| 203 | - | ||
| 204 | - | ||
| 205 | - | ||
| 206 | - | ||
| 207 | - | ||
| 179 | + | jsonConf; | |
| 180 | + | var | |
| 181 | + | cfg: TJSONConfig; | |
| 182 | + | List: TStringList; | |
| 183 | + | path: string; | |
| 184 | + | begin | |
| 185 | + | List:= TStringList.Create; | |
| 186 | + | cfg:= TJSONConfig.Create(nil); | |
| 187 | + | try | |
| 188 | + | //try/except to handle broken json file | |
| 189 | + | try | |
| 190 | + | cfg.Formatted:= true; | |
| 191 | + | cfg.Filename:= AJsonFilename; | |
| 192 | + | except | |
| 193 | + | exit; | |
| 194 | + | end; | |
| 195 | + | ||
| 196 | + | cfg.GetValue('/mylist', List, ''); | |
| 197 | + | List.Add('some_value'); | |
| 198 | + | cfg.SetValue('/mylist', List); | |
| 199 | + | finally | |
| 200 | + | cfg.Free; | |
| 201 | + | List.Free; | |
| 202 | + | end; | |
| 208 | 203 | ``` | |
| 209 | 204 | ||
| 210 | 205 | ## From JsonViewer | |
| 211 | 206 | ||
| 212 | - | ||
| 213 | - | ||
| 214 | - | ||
| 207 | + | Example usage can be found in the Lazarus jsonviewer tool (located in lazarus/tools/jsonviewer). In particular, this part of the tool shows how a json file is read into a TTreeView (named "TVJSON", in the code): | |
| 208 | + | ``` | |
| 215 | 209 | procedure TMainForm.OpenFile(Const AFileName : String); | |
| 216 | - | ||
| 217 | - | ||
| 218 | - | ||
| 219 | - | ||
| 220 | - | ||
| 221 | - | ||
| 222 | - | ||
| 223 | - | ||
| 224 | - | ||
| 225 | - | ||
| 226 | - | ||
| 227 | - | ||
| 228 | - | ||
| 229 | - | ||
| 230 | - | ||
| 231 | - | ||
| 232 | - | ||
| 233 | - | ||
| 234 | - | ||
| 235 | - | ||
| 236 | - | ||
| 237 | - | ||
| 238 | - | ||
| 239 | - | ||
| 240 | - | ||
| 241 | - | ||
| 242 | - | ||
| 243 | - | ||
| 244 | - | ||
| 245 | - | ||
| 246 | - | ||
| 247 | - | ||
| 248 | - | ||
| 249 | - | ||
| 250 | - | ||
| 251 | - | ||
| 252 | - | ||
| 210 | + | var | |
| 211 | + | S : TFileStream; | |
| 212 | + | P : TJSONParser; | |
| 213 | + | D : TJSONData; | |
| 214 | + | begin | |
| 215 | + | S:=TFileStream.Create(AFileName,fmOpenRead); | |
| 216 | + | try | |
| 217 | + | P:=TJSONParser.Create(S); | |
| 218 | + | try | |
| 219 | + | P.Strict:=FStrict; | |
| 220 | + | D:=P.Parse; | |
| 221 | + | finally | |
| 222 | + | P.Free; | |
| 253 | 223 | end; | |
| 254 | - | ||
| 255 | - | ||
| 224 | + | finally | |
| 225 | + | S.Free; | |
| 226 | + | end; | |
| 227 | + | FFileName:=AFileName; | |
| 228 | + | SetCaption; | |
| 229 | + | FreeAndNil(FRoot); | |
| 230 | + | FRoot:=D; | |
| 231 | + | ShowJSONDocument; | |
| 256 | 232 | end; | |
| 257 | - | ||
| 258 | - | ||
| 259 | - | ||
| 260 | - | ||
| 261 | - | ||
| 262 | - | ||
| 263 | - | ||
| 264 | - | ||
| 265 | - | ||
| 266 | - | ||
| 267 | - | ||
| 268 | - | ||
| 269 | - | ||
| 270 | - | ||
| 271 | - | ||
| 272 | - | ||
| 273 | - | ||
| 274 | - | ||
| 275 | - | ||
| 276 | - | ||
| 277 | - | ||
| 278 | - | ||
| 279 | - | ||
| 280 | - | ||
| 281 | - | ||
| 282 | - | ||
| 283 | - | ||
| 284 | - | ||
| 285 | - | ||
| 286 | - | ||
| 287 | - | ||
| 288 | - | ||
| 289 | - | ||
| 233 | + | ||
| 234 | + | procedure TMainForm.ShowJSONDocument; | |
| 235 | + | begin | |
| 236 | + | with TVJSON.Items do | |
| 237 | + | begin | |
| 238 | + | BeginUpdate; | |
| 239 | + | try | |
| 240 | + | TVJSON.Items.Clear; | |
| 241 | + | SHowJSONData(Nil,FRoot); | |
| 242 | + | with TVJSON do | |
| 243 | + | if (Items.Count>0) and Assigned(Items[0]) then | |
| 290 | 244 | begin | |
| 291 | - | ||
| 292 | - | ||
| 293 | - | ||
| 294 | - | ||
| 295 | - | ||
| 296 | - | ||
| 297 | - | ||
| 298 | - | ||
| 299 | - | ||
| 245 | + | Items[0].Expand(False); | |
| 246 | + | Selected:=Items[0]; | |
| 247 | + | end; | |
| 248 | + | finally | |
| 249 | + | EndUpdate; | |
| 300 | 250 | end; | |
| 301 | - | ||
| 302 | - | ||
| 303 | - | ||
| 304 | - | ||
| 251 | + | end; | |
| 305 | 252 | end; | |
| 306 | - | ||
| 253 | + | ||
| 254 | + | procedure TMainForm.ShowJSONData(AParent : TTreeNode; Data : TJSONData); | |
| 255 | + | var | |
| 256 | + | N,N2 : TTreeNode; | |
| 257 | + | I : Integer; | |
| 258 | + | D : TJSONData; | |
| 259 | + | C : String; | |
| 260 | + | S : TStringList; | |
| 307 | 261 | begin | |
| 308 | - | ||
| 309 | - | ||
| 310 | - | ||
| 262 | + | N:=Nil; | |
| 263 | + | if Assigned(Data) then | |
| 264 | + | begin | |
| 265 | + | case Data.JSONType of | |
| 266 | + | jtArray, | |
| 267 | + | jtObject: | |
| 268 | + | begin | |
| 269 | + | if (Data.JSONType=jtArray) then | |
| 270 | + | C:=SArray | |
| 271 | + | else | |
| 272 | + | C:=SObject; | |
| 273 | + | N:=TVJSON.Items.AddChild(AParent,Format(C,[Data.Count])); | |
| 274 | + | S:=TstringList.Create; | |
| 275 | + | try | |
| 276 | + | for I:=0 to Data.Count-1 do | |
| 277 | + | if Data.JSONtype=jtArray then | |
| 278 | + | S.AddObject(IntToStr(I),Data.items[i]) | |
| 279 | + | else | |
| 280 | + | S.AddObject(TJSONObject(Data).Names[i],Data.items[i]); | |
| 281 | + | if FSortObjectMembers and (Data.JSONType=jtObject) then | |
| 282 | + | S.Sort; | |
| 283 | + | for I:=0 to S.Count-1 do | |
| 284 | + | begin | |
| 285 | + | N2:=TVJSON.Items.AddChild(N,S[i]); | |
| 286 | + | D:=TJSONData(S.Objects[i]); | |
| 287 | + | N2.ImageIndex:=ImageTypeMap[D.JSONType]; | |
| 288 | + | N2.SelectedIndex:=ImageTypeMap[D.JSONType]; | |
| 289 | + | ShowJSONData(N2,D); | |
| 290 | + | end | |
| 291 | + | finally | |
| 292 | + | S.Free; | |
| 293 | + | end; | |
| 294 | + | end; | |
| 295 | + | jtNull: | |
| 296 | + | N:=TVJSON.Items.AddChild(AParent,SNull); | |
| 297 | + | else | |
| 298 | + | N:=TVJSON.Items.AddChild(AParent,Data.AsString); | |
| 299 | + | end; | |
| 300 | + | if Assigned(N) then | |
| 301 | + | begin | |
| 302 | + | N.ImageIndex:=ImageTypeMap[Data.JSONType]; | |
| 303 | + | N.SelectedIndex:=ImageTypeMap[Data.JSONType]; | |
| 304 | + | N.Data:=Data; | |
| 305 | + | end; | |
| 306 | + | end; | |
| 311 | 307 | end; | |
| 312 | - | ||
| 313 | - | ||
| 314 | 308 | ``` | |
| 315 | 309 | ||
| 316 | 310 | ## Change formatting of float numbers | |
| 317 | 311 | ||
| 318 | - | ||
| 319 | - | ||
| 320 | - | ||
| 321 | - | ||
| 322 | - | ||
| 323 | - | ||
| 324 | - | ||
| 312 | + | Q: My program generates and writes data to JSON file. I use FormatJSON() method to make output more readable. I'm not quite satisfied how numbers with float point look: | |
| 325 | 313 | ``` | |
| 326 | - | ||
| 327 | - | ||
| 328 | - | ||
| 329 | - | ||
| 330 | - | ||
| 331 | - | ||
| 332 | - | ||
| 333 | - | ||
| 314 | + | "coordinates" : [ | |
| 315 | + | 5.5978631048365003E+001, | |
| 316 | + | 2.2100000000000000E+002 | |
| 317 | + | ] | |
| 334 | 318 | ``` | |
| 335 | 319 | ||
| 336 | - | ||
| 320 | + | I want to see normal form: | |
| 321 | + | ``` | |
| 322 | + | "coordinates" : [ | |
| 323 | + | 55.978631048365003, | |
| 324 | + | 221.0 | |
| 325 | + | ] | |
| 326 | + | ``` | |
| 337 | 327 | ||
| 338 | - | ||
| 328 | + | A (forum members **y.ivanov** , **rvk** , **wp**): | |
| 329 | + | ``` | |
| 339 | 330 | {$mode objfpc}{$h+} | |
| 340 | - | ||
| 341 | - | ||
| 342 | - | ||
| 343 | - | ||
| 344 | - | ||
| 345 | - | ||
| 346 | - | ||
| 347 | - | ||
| 348 | - | ||
| 349 | - | ||
| 350 | - | ||
| 351 | - | ||
| 352 | - | ||
| 353 | - | ||
| 354 | - | ||
| 355 | - | ||
| 356 | - | ||
| 357 | - | ||
| 358 | - | ||
| 359 | - | ||
| 360 | - | ||
| 361 | - | ||
| 362 | - | ||
| 363 | - | ||
| 364 | - | ||
| 365 | - | ||
| 366 | - | ||
| 367 | - | ||
| 368 | - | ||
| 369 | - | ||
| 370 | - | ||
| 371 | - | ||
| 372 | - | ||
| 373 | - | ||
| 374 | - | ||
| 375 | - | ||
| 331 | + | uses | |
| 332 | + | fpjson, | |
| 333 | + | jsonparser, | |
| 334 | + | SysUtils; | |
| 335 | + | ||
| 336 | + | type | |
| 337 | + | TJSONFloat4Number = class(TJSONFloatNumber) | |
| 338 | + | protected | |
| 339 | + | function GetAsString: TJSONStringType; override; | |
| 340 | + | end; | |
| 341 | + | ||
| 342 | + | function TJSONFloat4Number.GetAsString: TJSONStringType; | |
| 343 | + | var | |
| 344 | + | F: TJSONFloat; | |
| 345 | + | fs: TFormatSettings; | |
| 346 | + | begin | |
| 347 | + | fs := DefaultFormatSettings; | |
| 348 | + | fs.DecimalSeparator := '.'; | |
| 349 | + | F := GetAsFloat; | |
| 350 | + | Result := FormatFloat('0.0###############', F, fs); // format with your preferences | |
| 351 | + | end; | |
| 352 | + | ||
| 353 | + | procedure JSONTest; | |
| 354 | + | var | |
| 355 | + | jData: TJSONData; | |
| 356 | + | begin | |
| 357 | + | jData := GetJSON('{"coordinates": [5.5978631048365003E+001, 2.2100000000000000E+002]}'); | |
| 358 | + | writeln(jData.FormatJSON); | |
| 359 | + | jData.Free; | |
| 360 | + | end; | |
| 361 | + | ||
| 362 | + | begin | |
| 363 | + | SetJSONInstanceType(jitNumberFloat, TJSONFloat4Number); | |
| 364 | + | JSONTest; | |
| 365 | + | Readln; | |
| 366 | + | end. | |
| 376 | 367 | ``` | |
| 377 | 368 | ||
| 378 | 369 | ## See also | |
| 379 | 370 | ||
| 380 | - | ||
| 381 | - | ||
| 382 | - | ||
| 383 | - | ||
| 371 | + | * The FpcTwit example in the [[Components and Code examples]] library makes use of JSON to send/receive data. | |
| 372 | + | * [FCL Reference](<https://www.freepascal.org/docs-html/fcl/index.html>) for unit fpjson. | |
| 373 | + | * [An article (PDF)](<http://www.freepascal.org/~michael/articles/webdata/webdata.pdf>) covering use of XML and JSON in FreePascal. | |
| 374 | + | * [[Package List]] | |
| 384 | 375 | ||
| 385 | 376 | --- | |
| 386 | - | ||
| 377 | + | *From the Free Pascal wiki, page "fcl-json", as the Internet Archive kept it on 2025-11-14, last changed on 2025-10-26. Copyright stays with the author who wrote it, according to the old wiki's [[Licensing]] page. If you have concerns about this material, [message the admin](/wiki-contact).* |
