I get, some hours ago, the book JSON Quick Syntax Reference by Wallace Jackson at my local library. I forgot that I can do that !
But it does not help me to understand how to decode a loaded json file beyond where I am stuck. For your understanding, heres a json example (extract) and what I get in the Listbox with my current code:
a. json file extract:
[
{"PNom":"Prénom","Nom":"Nom","Wife":"Épouse","Date_Birth":"Né(e) le","Pays":"Pays"},
{"ID":1,"PNom":"Jan","Nom":"Abad","Wife":"","Date_Birth":"1959-03-18","Pays":"Arménie"},
{"ID":2,"PNom":"Karen","Nom":"Turner","Wife":"","Date_Birth":"1990-08-24","Pays":"Arménie"},
{"ID":3,"PNom":"Bruce","Nom":"Jackson","Wife":"","Date_Birth":"1972-03-04","Pays":"Algérie"}
]
The file have 1978 entries, I only show the first 3 (and changed the actual First Names and Family Name).
I removed some entries to not confuse the reader, but in the real file, I have 11 entries in each file (inside {}).
b. The used code:
I do not show the other Dim variables, the .json file selection (OpenFI); these are useless for the understanding.
[code] Try
OpenTIS = TextInputStream.Open(OpenFI)
Dim JSONName, JSONValue as String
Dim Loop_Idx As Integer
Dim MyJasonCnt As Integer
Try
MyJason.Constructor(OpenTIS.ReadAll)
MyJasonCnt = MyJason.Count - 1
LB.AddRow "JSON Childs #: " + Str(MyJasonCnt)
LB.ColumnCount = MyJason.Child(0).Count - 1 // Complex, but working
Dim SingleJason As New JSONItem
Dim SingleJasonCnt As Integer
For Loop_Idx = 0 to MyJasonCnt
SingleJason = MyJason.Value(Loop_Idx)
SingleJasonCnt = SingleJason.Count - 1
Dim TheJSON As JSONItem
For Col_Idx As Integer = 0 to SingleJasonCnt
JSONName = SingleJason.Name(Col_Idx)
LB.AddRow JSONName
If UserCancelled Then Exit
Next
If UserCancelled Then Exit
Next
OpenTIS.Close
Catch e As JSONException
OpenTIS.Close
MsgBox "Import JSON into Caritas Data Base" + EndOfLine + EndOfLine +_
"Error trying to convert the JSON data."
End Try
Catch e As IOException
OpenTIS.Close
MsgBox “Import JSON into Caritas Data Base” + EndOfLine + EndOfLine +_
“Error trying to read the JSON text file.”
End Try[/code]
I removed the comments to keep the post as light as possible (!).
c. The result:
I get the first (left) part of each array into the Listbox. Say I get in the Listbox Column 1 “ID” (without the quotes), not the number value (1, 2? 3, 4, thru 1978).
For Column 2, I get (in each Row) PNom instead of the real first names (Jan, Karen, Bruce, ect for the 1978 entries), and so on.
d. Where will I use this feature ?
As is (or so) in a project, store the data inside a SQLite data base file (instead of a Listbox) in a ProBono project (for Caritas).
Some help is welcome.