I am stuck with reading a json file

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, here’s 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


  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

    If UserCancelled Then Exit


Catch e As JSONException
  MsgBox "Import JSON into Caritas Data Base" + EndOfLine + EndOfLine +_
  "Error trying to convert the JSON data."
End Try

Catch e As IOException
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.

I have a stupid idea while watching TV and reading advertising papers for supermarket stuff:

LB.AddRow ""+ SingleJason.Value(JSONName)

Without the leading “” + , I get an un…understandable error message.

All I have to do now is to move LB.AddRow “” before the start of the Col_Idx loop and modify a bit the code inside that loop and it will be OK.

Too bad: it worked once and stopped after I modified the code to only add one row ad fill its cells:

LB.Cell(Loc_Row,Col_Idx) = "" + SingleJason.Value(JSONName)

It may be time for me to quit xojo 'till tomorrow…

I much prefer the new framework JSON item, but with the classic JSONItem you can see how I’ve done it in this project.

See my answer in your other thread. I hope it helps you understand the format of your json string.

I got it. Thanks.