Reading a JSONItem…

In the code below, I get a JSONException in the second line. My JSONItem is an array. As far as I can understand, I create a JSON array and all the examples I found seems to use a JSON Dictionary.

Help !

teamName = league.Name(i) team = league.Value(teamName)

“Help me if you can I’m feeling down…” Before I start to decode by myself the JSON text file (using NthField, CountFields and a bunch of Loops…)

Json arrays can only be accessed by index, not by name. It would help considerably if you posted a sample of the json you are dealing with.

You should also look at the ErrorMessage property of the exception itself. It may tell you what the error is.

Thank you for your answers.

Tim, here’s an example:

[
{
“PNom”:“Prénom”,
“Nom”:“Nom”,
“Wife”:“Épouse”,
“Enfant”:“Enfant”,
“Sexe”:“H \/ F”,
“Date_Birth”:“Né(e) le”,
“Pays”:“Pays”,
“SentBy”:“Envoyé par”,
“Date_In”:“Entré(e) le”,
“Date_Out”:“Sorti(e) le”,
“Status”:“Statut”
},
{

and so on. The text above is the strings for the Listbox Header. The Rows follow the same schema (definition), excepted for the right part who holds first name, name, wife name, child, Sexe (H: Man, F: Woman in French), etc.

BTW: the slash is escaped (H \/ F)… :wink:

Greg: no more error message. I only get ‘:’ (without the quotes) when I add a row in the target Listbox.

BTW: I can get the number of entries in the JSONItem (around 1970, same as RecordSet in the source sqlite data base file).

So, if I want to get a JSONitem (I think a specific RecordSet), I have to code:

Single_JSONItem = MyJSON.Value(Loop_Idx) ?

I go test that… No. I get a JSONException.

[code] For Loop_Idx = 1 to MyJasonCnt // As I wrote earlier, I get the number of entries in the array
SingleJason = MyJason.Value(Loop_Idx) // I tried to get a JSON entry (it have 11 “fields”

    JSONName = SingleJason.Value(0) // 0 for the test…[/code]

This:

[code] For Loop_Idx = 0 to MyJasonCnt
SingleJason = MyJason.Value(Loop_Idx)
SingleJasonCnt = SingleJason.Count - 1

    Dim TheJSON As JSONItem
    
    For j As Integer = 0 to SingleJasonCnt
      JSONName = SingleJason.Name(j)
      
      LB.AddRow JSONName

      If UserCancelled Then Exit
    Next
  If UserCancelled Then Exit
Next[/code]

Fills the Listbox with the column names: left part of the JSON, not the right part, the part I want.

I tried: JSONName = SingleJason.Value(j), but this does not work. The error is… strange !

JSONItem is not an array.
ExceptionError Number 12.

MyJson is a json array. (An array of JsonItems)
SingeJson is a regular JsonItem, not an array. It’s values can be accessed by name.

SingleJson = MyJson.value(Loop_Idx)   // array access
LB.AddRow SingleJson.value("PNom")  // regular access
LB.AddRow SingleJson.value("Nom")
LB.AddRow SingleJson.value("Wife")
etc.

A Jsonitem can be a group of name/value pairs, or an array of JsonItem.
A JsonItem begins with “{” and ends with “}”
An array begins with “[” and ends with “]”

Thanks Tim.