json.bmx 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800
  1. ' Copyright (c) 2014-2020 Bruce A Henderson
  2. '
  3. ' Permission is hereby granted, free of charge, to any person obtaining a copy
  4. ' of this software and associated documentation files (the "Software"), to deal
  5. ' in the Software without restriction, including without limitation the rights
  6. ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  7. ' copies of the Software, and to permit persons to whom the Software is
  8. ' furnished to do so, subject to the following conditions:
  9. '
  10. ' The above copyright notice and this permission notice shall be included in
  11. ' all copies or substantial portions of the Software.
  12. '
  13. ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  14. ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  15. ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  16. ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  17. ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  18. ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  19. ' THE SOFTWARE.
  20. '
  21. SuperStrict
  22. Rem
  23. bbdoc: A JSON encoder/decoder.
  24. End Rem
  25. Module Text.Json
  26. ModuleInfo "Version: 1.04"
  27. ModuleInfo "Author: Bruce A Henderson"
  28. ModuleInfo "License: MIT"
  29. ModuleInfo "Copyright: 2014-2020 Bruce A Henderson"
  30. ModuleInfo "History: 1.04"
  31. ModuleInfo "History: Added index operator overloading to TJSONArray."
  32. ModuleInfo "History: Added TJSONBool Create method."
  33. ModuleInfo "History: 1.03"
  34. ModuleInfo "History: Updated to Jansson 2.12"
  35. ModuleInfo "History: 1.02"
  36. ModuleInfo "History: Updated to Jansson 2.10.009ffa3"
  37. ModuleInfo "History: Added errorCode field to TJSONError."
  38. ModuleInfo "History: 1.01"
  39. ModuleInfo "History: Updated to Jansson 2.10"
  40. ModuleInfo "History: 1.00"
  41. ModuleInfo "History: Initial Release"
  42. ModuleInfo "CC_OPTS: -DHAVE_CONFIG_H"
  43. Import "common.bmx"
  44. Rem
  45. bbdoc: Base type for JSON objects.
  46. End Rem
  47. Type TJSON
  48. Field jsonPtr:Byte Ptr
  49. Field key:String
  50. Function _create:TJSON(jsonPtr:Byte Ptr, jsonType:Int, key:String) { nomangle }
  51. Local this:TJSON
  52. Select jsonType
  53. Case JSON_TYPE_OBJECT
  54. this = New TJSONObject
  55. Case JSON_TYPE_ARRAY
  56. this = New TJSONArray
  57. Case JSON_TYPE_STRING
  58. this = New TJSONString
  59. Case JSON_TYPE_INTEGER
  60. this = New TJSONInteger
  61. Case JSON_TYPE_REAL
  62. this = New TJSONReal
  63. Case JSON_TYPE_TRUE
  64. this = New TJSONBool
  65. TJSONBool(this).isTrue = True
  66. Case JSON_TYPE_FALSE
  67. this = New TJSONBool
  68. Case JSON_TYPE_NULL
  69. this = New TJSONNull
  70. Default
  71. Return Null
  72. End Select
  73. this.jsonPtr = jsonPtr
  74. this.key = key
  75. Return this
  76. End Function
  77. Rem
  78. bbdoc: Returns the JSON representation of the object as a String, or NULL on error.
  79. about: Valid flags include #JSON_COMPACT, #JSON_ENSURE_ASCII, #JSON_SORT_KEYS, #JSON_PRESERVE_ORDER, #JSON_ENCODE_ANY and #JSON_ESCAPE_SLASH.
  80. End Rem
  81. Method SaveString:String(flags:Int = 0, indent:Int = 0, precision:Int = 17)
  82. Return bmx_json_dumps(jsonPtr, flags, indent, precision)
  83. End Method
  84. Rem
  85. bbdoc: Writes the JSON representation of the object to the stream output.
  86. about: The stream should already be open for writing.
  87. Valid flags include #JSON_COMPACT, #JSON_ENSURE_ASCII, #JSON_SORT_KEYS, #JSON_PRESERVE_ORDER, #JSON_ENCODE_ANY and #JSON_ESCAPE_SLASH.
  88. End Rem
  89. Method SaveStream:Int(stream:TStream, flags:Int = 0, indent:Int = 0, precision:Int = 17)
  90. Return bmx_json_dump_callback(jsonPtr, _dumpCallback, stream, flags, indent, precision)
  91. End Method
  92. Rem
  93. bbdoc: Loads JSON text from a String or TStream.
  94. about: The stream should already be open for reading.
  95. Valid flags include #JSON_REJECT_DUPLICATES, #JSON_DISABLE_EOF_CHECK, #JSON_DECODE_ANY, #JSON_DECODE_INT_AS_REAL and #JSON_ALLOW_NUL.
  96. End Rem
  97. Function Load:TJSON(data:Object, flags:Int = 0, error:TJSONError Var)
  98. Local err:TJSONError
  99. If String(data) Then
  100. ' load as text
  101. err = TJSONError(bmx_json_loads(String(data), flags))
  102. Else If TStream(data) Then
  103. ' load as stream
  104. err = TJSONError(bmx_json_load_callback(_loadCallback, TStream(data), flags))
  105. End If
  106. If err
  107. If err._js Then
  108. Return err._js
  109. End If
  110. error = err
  111. End If
  112. Return Null
  113. End Function
  114. ?bmxng
  115. Function _loadCallback:Size_T(buffer:Byte Ptr, buflen:Size_T, data:TStream)
  116. ?Not bmxng
  117. Function _loadCallback:Int(buffer:Byte Ptr, buflen:Int, data:TStream)
  118. ?
  119. Return data.Read(buffer, buflen)
  120. End Function
  121. ?bmxng
  122. Function _dumpCallback:Size_T(buffer:Byte Ptr, size:Size_T, data:TStream)
  123. ?Not bmxng
  124. Function _dumpCallback:Int(buffer:Byte Ptr, size:Int, data:TStream)
  125. ?
  126. Return data.Write(buffer, size)
  127. End Function
  128. Method Delete()
  129. If jsonPtr Then
  130. bmx_json_decref(jsonPtr)
  131. jsonPtr = Null
  132. End If
  133. End Method
  134. End Type
  135. Rem
  136. bbdoc: A JSON array is an ordered collection of other JSON values.
  137. End Rem
  138. Type TJSONArray Extends TJSON
  139. Rem
  140. bbdoc: Creates a new TJSONArray.
  141. End Rem
  142. Method Create:TJSONArray()
  143. jsonPtr = json_array()
  144. Return Self
  145. End Method
  146. Rem
  147. bbdoc: Returns the number of elements in array, or 0 if array is NULL
  148. End Rem
  149. Method Size:Int()
  150. Return bmx_json_array_size(jsonPtr)
  151. End Method
  152. Rem
  153. bbdoc: Returns the element in array at position index.
  154. about: The valid range for index is from 0 to the return value of Size() minus 1. If index is out of range, NULL is returned.
  155. End Rem
  156. Method Get:TJSON(index:Int)
  157. Return TJSON(bmx_json_array_get(jsonPtr, index))
  158. End Method
  159. Rem
  160. bbdoc: Replaces the element in array at position index with value.
  161. returns: 0 on success and -1 on error.
  162. End Rem
  163. Method Set:Int(index:Int, value:TJSON)
  164. Return bmx_json_array_set(jsonPtr, index, value.jsonPtr)
  165. End Method
  166. Rem
  167. bbdoc: Appends value to the end of array, growing the size of array by 1.
  168. returns: 0 on success and -1 on error.
  169. End Rem
  170. Method Append:Int(value:TJSON)
  171. Return bmx_json_array_append(jsonPtr, value.jsonPtr)
  172. End Method
  173. Rem
  174. bbdoc: Inserts @value to array at position @index, shifting the elements at index and after it one position towards the end of the array.
  175. returns: 0 on success and -1 on error.
  176. End Rem
  177. Method Insert:Int(index:Int, value:TJSON)
  178. Return bmx_json_array_insert(jsonPtr, index, value.jsonPtr)
  179. End Method
  180. Rem
  181. bbdoc: Removes all elements from array.
  182. returns: 0 on sucess and -1 on error.
  183. End Rem
  184. Method Clear:Int()
  185. Return json_array_clear(jsonPtr)
  186. End Method
  187. Rem
  188. bbdoc: Removes the element in array at position index, shifting the elements after index one position towards the start of the array.
  189. returns: 0 on success and -1 on error.
  190. End Rem
  191. Method Remove:Int(index:Int)
  192. Return json_array_remove(jsonPtr, index)
  193. End Method
  194. Method ObjectEnumerator:TJSONArrayEnum()
  195. Local enumeration:TJSONArrayEnum =New TJSONArrayEnum
  196. enumeration.array = Self
  197. Return enumeration
  198. End Method
  199. Rem
  200. bbdoc: Returns the element in array at position index.
  201. about: The valid range for index is from 0 to the return value of Size() minus 1. If index is out of range, NULL is returned.
  202. End Rem
  203. Method Operator [] :TJSON(index:Int)
  204. Return Get(index)
  205. End Method
  206. Rem
  207. bbdoc: Replaces the element in array at position index with value.
  208. End Rem
  209. Method Operator []= (index:Int, value:TJSON)
  210. Set(index, value)
  211. End Method
  212. End Type
  213. Type TJSONArrayEnum
  214. Field array:TJSONArray
  215. Field index:Int
  216. Method HasNext:Int()
  217. Return index < array.Size()
  218. End Method
  219. Method NextObject:Object()
  220. Local value:Object=array.Get(index)
  221. index:+ 1
  222. Return value
  223. End Method
  224. End Type
  225. Rem
  226. bbdoc: A JSON object is a dictionary of key-value pairs, where the key is a Unicode string and the value is any JSON value.
  227. End Rem
  228. Type TJSONObject Extends TJSON
  229. Rem
  230. bbdoc: Creates a new TJSONObject.
  231. End Rem
  232. Method Create:TJSONObject()
  233. jsonPtr = json_object()
  234. Return Self
  235. End Method
  236. Rem
  237. bbdoc: Returns the number of elements in the object.
  238. End Rem
  239. Method Size:Int()
  240. Return bmx_json_object_size(jsonPtr)
  241. End Method
  242. Rem
  243. bbdoc: Gets a value corresponding to key from the object.
  244. returns: Null if key is not found or on error.
  245. End Rem
  246. Method Get:TJSON(key:String)
  247. Return TJSON(bmx_json_object_get(jsonPtr, key))
  248. End Method
  249. Rem
  250. bbdoc: Sets the value of key to value in the object.
  251. returns: 0 on success and -1 on error.
  252. about: If there already is a value for key, it is replaced by the new value.
  253. End Rem
  254. Method Set:Int(key:String, value:TJSON)
  255. Return bmx_json_object_set_nocheck(jsonPtr, key, value.jsonPtr)
  256. End Method
  257. Rem
  258. bbdoc: Sets the value of key To the #String value.
  259. returns: 0 on success and -1 on error.
  260. about: If there already is a value for key, it is replaced by the new value.
  261. End Rem
  262. Method Set:Int(key:String, value:String)
  263. Local v:TJSONString = New TJSONString.Create(value)
  264. Return bmx_json_object_set_nocheck(jsonPtr, key, v.jsonPtr)
  265. End Method
  266. Rem
  267. bbdoc: Sets the value of key to the #Int value.
  268. returns: 0 on success and -1 on error.
  269. about: If there already is a value for key, it is replaced by the new value.
  270. End Rem
  271. Method Set:Int(key:String, value:Int)
  272. Local v:TJSONInteger = New TJSONInteger.Create(value)
  273. Return bmx_json_object_set_nocheck(jsonPtr, key, v.jsonPtr)
  274. End Method
  275. Rem
  276. bbdoc: Sets the value of key to the #Short value.
  277. returns: 0 on success and -1 on error.
  278. about: If there already is a value for key, it is replaced by the new value.
  279. End Rem
  280. Method Set:Int(key:String, value:Short)
  281. Local v:TJSONInteger = New TJSONInteger.Create(value)
  282. Return bmx_json_object_set_nocheck(jsonPtr, key, v.jsonPtr)
  283. End Method
  284. Rem
  285. bbdoc: Sets the value of key to the #Byte value.
  286. returns: 0 on success and -1 on error.
  287. about: If there already is a value for key, it is replaced by the new value.
  288. End Rem
  289. Method Set:Int(key:String, value:Byte)
  290. Local v:TJSONInteger = New TJSONInteger.Create(value)
  291. Return bmx_json_object_set_nocheck(jsonPtr, key, v.jsonPtr)
  292. End Method
  293. Rem
  294. bbdoc: Sets the value of key to the #Long value.
  295. returns: 0 on success and -1 on error.
  296. about: If there already is a value for key, it is replaced by the new value.
  297. End Rem
  298. Method Set:Int(key:String, value:Long)
  299. Local v:TJSONInteger = New TJSONInteger.Create(value)
  300. Return bmx_json_object_set_nocheck(jsonPtr, key, v.jsonPtr)
  301. End Method
  302. Rem
  303. bbdoc: Sets the value of key to the #UInt value.
  304. returns: 0 on success and -1 on error.
  305. about: If there already is a value for key, it is replaced by the new value.
  306. End Rem
  307. Method Set:Int(key:String, value:UInt)
  308. Local v:TJSONInteger = New TJSONInteger.Create(value)
  309. Return bmx_json_object_set_nocheck(jsonPtr, key, v.jsonPtr)
  310. End Method
  311. Rem
  312. bbdoc: Sets the value of key to the #ULong value.
  313. returns: 0 on success and -1 on error.
  314. about: If there already is a value for key, it is replaced by the new value.
  315. End Rem
  316. Method Set:Int(key:String, value:ULong)
  317. Local v:TJSONInteger = New TJSONInteger.Create(Long(value))
  318. Return bmx_json_object_set_nocheck(jsonPtr, key, v.jsonPtr)
  319. End Method
  320. Rem
  321. bbdoc: Sets the value of key to the #Size_t value.
  322. returns: 0 on success and -1 on error.
  323. about: If there already is a value for key, it is replaced by the new value.
  324. End Rem
  325. Method Set:Int(key:String, value:Size_T)
  326. Local v:TJSONInteger = New TJSONInteger.Create(Long(value))
  327. Return bmx_json_object_set_nocheck(jsonPtr, key, v.jsonPtr)
  328. End Method
  329. Rem
  330. bbdoc: Sets the value of key to the #Float value.
  331. returns: 0 on success and -1 on error.
  332. about: If there already is a value for key, it is replaced by the new value.
  333. End Rem
  334. Method Set:Int(key:String, value:Float)
  335. Local v:TJSONReal = New TJSONReal.Create(value)
  336. Return bmx_json_object_set_nocheck(jsonPtr, key, v.jsonPtr)
  337. End Method
  338. Rem
  339. bbdoc: Sets the value of key to the #Double value.
  340. returns: 0 on success and -1 on error.
  341. about: If there already is a value for key, it is replaced by the new value.
  342. End Rem
  343. Method Set:Int(key:String, value:Double)
  344. Local v:TJSONReal = New TJSONReal.Create(value)
  345. Return bmx_json_object_set_nocheck(jsonPtr, key, v.jsonPtr)
  346. End Method
  347. Rem
  348. bbdoc: Deletes key from the Object If it exists.
  349. returns: 0 on success, or -1 if key was not found.
  350. End Rem
  351. Method Del:Int(key:String)
  352. Return bmx_json_object_del(jsonPtr, key)
  353. End Method
  354. Rem
  355. bbdoc: Removes all elements from the object.
  356. returns: 0 on success, -1 otherwise.
  357. End Rem
  358. Method Clear:Int()
  359. Return json_object_clear(jsonPtr)
  360. End Method
  361. Rem
  362. bbdoc: Updates the object with the key-value pairs from @other, overwriting existing keys.
  363. returns: 0 on success or -1 on error.
  364. End Rem
  365. Method Update:Int(other:TJSONObject)
  366. Return json_object_update(jsonPtr, other.jsonPtr)
  367. End Method
  368. Rem
  369. bbdoc: Updates the object with the key-value pairs from @other, but only the values of existing keys are updated.
  370. returns: 0 on success or -1 on error.
  371. about: No new keys are created.
  372. End Rem
  373. Method UpdateExisting:Int(other:TJSONObject)
  374. Return json_object_update_existing(jsonPtr, other.jsonPtr)
  375. End Method
  376. Rem
  377. bbdoc: Updates the object with the key-value pairs from @other, but only new keys are created.
  378. returns: 0 on success or -1 on error.
  379. about: The value of any existing key is not changed.
  380. End Rem
  381. Method UpdateMissing:Int(other:TJSONObject)
  382. Return json_object_update_missing(jsonPtr, other.jsonPtr)
  383. End Method
  384. Method ObjectEnumerator:TJSONObjectEnum()
  385. Local enumeration:TJSONObjectEnum =New TJSONObjectEnum
  386. enumeration.obj = Self
  387. enumeration.objectIter = json_object_iter(jsonPtr)
  388. Return enumeration
  389. End Method
  390. Rem
  391. bbdoc: Gets a String value corresponding to key from the object.
  392. returns: Null if key is not found, the value is not a String, or on error.
  393. End Rem
  394. Method GetString:String(key:String)
  395. Local s:TJSONString = TJSONString(bmx_json_object_get(jsonPtr, key))
  396. If s Then
  397. Return s.Value()
  398. End If
  399. End Method
  400. Rem
  401. bbdoc: Gets an Integer (Long) value corresponding to key from the object.
  402. returns: Null if key is not found, the value is not an Integer, or on error.
  403. End Rem
  404. Method GetInteger:Long(key:String)
  405. Local i:TJSONInteger = TJSONInteger(bmx_json_object_get(jsonPtr, key))
  406. If i Then
  407. Return i.Value()
  408. End If
  409. End Method
  410. Rem
  411. bbdoc: Gets a Real (Double) value corresponding to key from the object.
  412. returns: Null if key is not found, the value is not a Real, or on error.
  413. End Rem
  414. Method GetReal:Double(key:String)
  415. Local r:TJSONReal = TJSONReal(bmx_json_object_get(jsonPtr, key))
  416. If r Then
  417. Return r.Value()
  418. End If
  419. End Method
  420. Rem
  421. bbdoc: Gets a Boolean value corresponding to key from the object.
  422. returns: Null if key is not found, the value is not a Boolean, or on error.
  423. End Rem
  424. Method GetBool:Int(key:String)
  425. Local b:TJSONBool = TJSONBool(bmx_json_object_get(jsonPtr, key))
  426. If b Then
  427. Return b.isTrue
  428. End If
  429. End Method
  430. End Type
  431. Type TJSONObjectEnum
  432. Field obj:TJSONObject
  433. Field objectIter:Byte Ptr
  434. Method HasNext:Int()
  435. If objectIter Then
  436. Return True
  437. End If
  438. End Method
  439. Method NextObject:Object()
  440. Local value:Object = bmx_json_object_iter_value(objectIter)
  441. objectIter = json_object_iter_next(obj.jsonPtr, objectIter)
  442. Return value
  443. End Method
  444. End Type
  445. Rem
  446. bbdoc: A JSON String.
  447. End Rem
  448. Type TJSONString Extends TJSON
  449. Rem
  450. bbdoc: Creates a new TJSONString.
  451. End Rem
  452. Method Create:TJSONString(Text:String)
  453. jsonPtr = bmx_json_string_nocheck(Text)
  454. Return Self
  455. End Method
  456. Rem
  457. bbdoc: Returns the associated value of the string.
  458. End Rem
  459. Method Value:String()
  460. Return bmx_json_string_value(jsonPtr)
  461. End Method
  462. End Type
  463. Rem
  464. bbdoc: Base type for JSON number types.
  465. End Rem
  466. Type TJSONNumber Extends TJSON
  467. End Type
  468. Rem
  469. bbdoc: a JSON integer.
  470. End Rem
  471. Type TJSONInteger Extends TJSONNumber
  472. Rem
  473. bbdoc: Creates an instance of #TJSONInteger with @v.
  474. End Rem
  475. Method Create:TJSONInteger(v:Long)
  476. jsonPtr = bmx_json_integer(v)
  477. Return Self
  478. End Method
  479. Rem
  480. bbdoc: Creates an instance of #TJSONInteger with @v.
  481. End Rem
  482. Method Create:TJSONInteger(v:Byte)
  483. jsonPtr = bmx_json_integer(v)
  484. Return Self
  485. End Method
  486. Rem
  487. bbdoc: Creates an instance of #TJSONInteger with @v.
  488. End Rem
  489. Method Create:TJSONInteger(v:Short)
  490. jsonPtr = bmx_json_integer(v)
  491. Return Self
  492. End Method
  493. Rem
  494. bbdoc: Creates an instance of #TJSONInteger with @v.
  495. End Rem
  496. Method Create:TJSONInteger(v:Int)
  497. jsonPtr = bmx_json_integer(v)
  498. Return Self
  499. End Method
  500. Rem
  501. bbdoc: Creates an instance of #TJSONInteger with @v.
  502. End Rem
  503. Method Create:TJSONInteger(v:UInt)
  504. jsonPtr = bmx_json_integer(v)
  505. Return Self
  506. End Method
  507. Rem
  508. bbdoc: Creates an instance of #TJSONInteger with @v.
  509. End Rem
  510. Method Create:TJSONInteger(v:ULong)
  511. jsonPtr = bmx_json_integer(Long(v))
  512. Return Self
  513. End Method
  514. Rem
  515. bbdoc: Creates an instance of #TJSONInteger with @v.
  516. End Rem
  517. Method Create:TJSONInteger(v:Size_T)
  518. jsonPtr = bmx_json_integer(Long(v))
  519. Return Self
  520. End Method
  521. Rem
  522. bbdoc: Returns the associated value of the integer.
  523. End Rem
  524. Method Value:Long()
  525. Local v:Long
  526. bmx_json_integer_value(jsonPtr, Varptr v)
  527. Return v
  528. End Method
  529. Rem
  530. bbdoc: Sets the associated value of integer to @v.
  531. about: Returns 0 on success, -1 otherwise.
  532. End Rem
  533. Method Set:Int(v:Long)
  534. Return bmx_json_integer_set(jsonPtr, v)
  535. End Method
  536. Rem
  537. bbdoc: Sets the associated value of integer to @v.
  538. about: Returns 0 on success, -1 otherwise.
  539. End Rem
  540. Method Set:Int(v:Byte)
  541. Return bmx_json_integer_set(jsonPtr, v)
  542. End Method
  543. Rem
  544. bbdoc: Sets the associated value of integer to @v.
  545. about: Returns 0 on success, -1 otherwise.
  546. End Rem
  547. Method Set:Int(v:Short)
  548. Return bmx_json_integer_set(jsonPtr, v)
  549. End Method
  550. Rem
  551. bbdoc: Sets the associated value of integer to @v.
  552. about: Returns 0 on success, -1 otherwise.
  553. End Rem
  554. Method Set:Int(v:Int)
  555. Return bmx_json_integer_set(jsonPtr, v)
  556. End Method
  557. Rem
  558. bbdoc: Sets the associated value of integer to @v.
  559. about: Returns 0 on success, -1 otherwise.
  560. End Rem
  561. Method Set:Int(v:UInt)
  562. Return bmx_json_integer_set(jsonPtr, v)
  563. End Method
  564. Rem
  565. bbdoc: Sets the associated value of integer to @v.
  566. about: Returns 0 on success, -1 otherwise.
  567. End Rem
  568. Method Set:Int(v:ULong)
  569. Return bmx_json_integer_set(jsonPtr, Long(v))
  570. End Method
  571. Rem
  572. bbdoc: Sets the associated value of integer to @v.
  573. about: Returns 0 on success, -1 otherwise.
  574. End Rem
  575. Method Set:Int(v:Size_T)
  576. Return bmx_json_integer_set(jsonPtr, Long(v))
  577. End Method
  578. End Type
  579. Rem
  580. bbdoc: A JSON real number.
  581. End Rem
  582. Type TJSONReal Extends TJSONNumber
  583. Rem
  584. bbdoc: Creates an instance of #TJSONReal with @v.
  585. End Rem
  586. Method Create:TJSONReal(v:Double)
  587. jsonPtr = json_real(v)
  588. Return Self
  589. End Method
  590. Rem
  591. bbdoc: Creates an instance of #TJSONReal with @v.
  592. End Rem
  593. Method Create:TJSONReal(v:Float)
  594. jsonPtr = json_real(v)
  595. Return Self
  596. End Method
  597. Rem
  598. bbdoc: Returns the associated value of the real.
  599. End Rem
  600. Method Value:Double()
  601. Return json_real_value(jsonPtr)
  602. End Method
  603. Rem
  604. bbdoc: Sets the associated value of real to @v.
  605. about: Returns 0 on success, -1 otherwise.
  606. End Rem
  607. Method Set:Int(v:Double)
  608. Return json_real_set(jsonPtr, v)
  609. End Method
  610. Rem
  611. bbdoc: Sets the associated value of real to @v.
  612. about: Returns 0 on success, -1 otherwise.
  613. End Rem
  614. Method Set:Int(v:Float)
  615. Return json_real_set(jsonPtr, v)
  616. End Method
  617. End Type
  618. Rem
  619. bbdoc: A JSON boolean.
  620. End Rem
  621. Type TJSONBool Extends TJSON
  622. Field isTrue:Int
  623. Rem
  624. bbdoc: Creates an instance of #TJSONBool with @v.
  625. End Rem
  626. Method Create:TJSONBool(v:Int)
  627. jsonPtr = bmx_json_bool(v)
  628. isTrue = v
  629. Return Self
  630. End Method
  631. End Type
  632. Rem
  633. bbdoc: A JSON Null.
  634. End Rem
  635. Type TJSONNull Extends TJSON
  636. End Type
  637. Rem
  638. bbdoc: JSON error information.
  639. End Rem
  640. Type TJSONError
  641. Rem
  642. bbdoc: The error message, or an empty string if a message is not available.
  643. End Rem
  644. Field Text:String
  645. Rem
  646. bbdoc: Source of the error.
  647. about: This can be (a part of) the file name or a special identifier in angle brackers (e.g. &lt;string&gt;).
  648. End Rem
  649. Field source:String
  650. Rem
  651. bbdoc: The line number on which the error occurred.
  652. End Rem
  653. Field line:Int
  654. Rem
  655. bbdoc: The column on which the error occurred.
  656. about: Note that this is the character column, not the byte column, i.e. a multibyte UTF-8 character counts as one column.
  657. End Rem
  658. Field column:Int
  659. Rem
  660. bbdoc: The position in bytes from the start of the input.
  661. about: This is useful for debugging Unicode encoding problems.
  662. End Rem
  663. Field position:Int
  664. Rem
  665. bbdoc: The numeric code for the error.
  666. End Rem
  667. Field errorCode:Int
  668. Field _js:TJSON
  669. Function _createError:TJSONError(Text:String, source:String, line:Int, column:Int, position:Int, errorCode:Int) { nomangle }
  670. Local this:TJSONError = New TJSONError
  671. this.Text = Text
  672. this.source = source
  673. this.line = line
  674. this.column = column
  675. this.position = position
  676. this.errorCode = errorCode
  677. Return this
  678. End Function
  679. Function _createNoError:TJSONError(_js:TJSON) { nomangle }
  680. Local this:TJSONError = New TJSONError
  681. this._js = _js
  682. Return this
  683. End Function
  684. End Type