Reading &QUEUE in a GROUP for JSON.FromJSONFile()

I am trying to read a JSON file with a QUEUE inside two groups. Something like this:

MyGroup1 GROUP
MyGroup2 GROUP
MyQueueRef &QUEUE
END
END

MyQueue QUEUE
Name STRING(20)
Adress STRING(20 )
END

CODE

Some code…

MyQueueRef &= MyQueue

ERR# = JSON.FromJSONFile(respfile, MyGroup1)

LOOP I# = 1 TO RECORDS(MyQueueRef)
Fil:Name = MyQueueRef.Name
Fil:Adress = MyQueueRef.Adress
ADD(File)
END

I am obviously doing it wrong. I know the JSON file is OK. And is it what is inside the queue I need to read.

Help will be appreciated.

Trond

MyQueueRef is still a field inside a group which is inside a group.

It would be something like:

i Long

Code
Loop i = 1 to Records(MyGroup1.MyGroup2.MyQueueRef)
!Do Stuff
End

Thanks…
I simplified the example. I’ve tried that way, but it is still zero records in MyQueueRef.

“stop(RECORDS(BronnGroup._embedded.enheter.JSONQ))” = 0

Have you looked at:

www.capesoft.com/jfilescode

Insert your JSON and it can construct data structures and code for saving and loading the JSON using jFiles.

Might be worth a look.

1 Like

Oh…

This:

MyGroup1 GROUP
MyGroup2 GROUP
MyQueueRef &QUEUE
END
END

should probably be this:

MyGroup1 GROUP
MyGroup2 GROUP
MyQueueRef &MyQueue
END
END

and the queue:

MyQueue QUEUE,TYPE !<<-- TYPE
Name STRING(20)
Adress STRING(20 )
END

And…

MyGroup1.MyGroup2.MyQueueRef &= MyQueue

No I have not, but I will take a look tomorrow.

1 Like

Mayby this is the clue. I will try this out tomorrow, now it is 1:30 in Norway and I looking for my bed.

Thank you

1 Like

In cJSON package there is “Queue In Group” example. It parses input json into this group:

PersonGrp                       GROUP
Name                              STRING(20)
Addresses                         &QUEUE      !- reference to AddressQ
Phones                            &QUEUE      !- reference to PhonesQ
                                END

Then I get "Cannot use TYPEd structure in this way " error…

My apologies.

Try:

MyGroup1.MyGroup2.MyQueueRef &= NEW (MyQueue)

That’s what happens when you try to code with about 4 hours of sleep in 24 hours.

Does not seem to work either.
After “ERR# = JSON.FromJSONFile(respfile, MyGroup1)” the size of MyGroup1 is 4 bytes and still no records in the MyQueueRef queue.

Mike,
I have looked at your example, but I can’t figure out how to use that in my example.

If you’re able, email a copy of the JSON you’re trying to load to me and I’ll take a look.

I’ll send you an example app.

What version of Clarion are you using and do you have jFiles from Capesoft?

Trond,

Do it similarly.

It only took a few minutes using jFiles and StringTheory to parse your JSON.

I’ll ZIP up the app and send it to you.

Don

Trond JSON Example.zip (1.5 MB)

Here’s the example app.

It does make use of jFiles2 and StringTheory. Both are worth their weight in gold for parsing JSON.

Thank you very much Donald, but I do not have jFiles2 or StringTheory. The problem is that I am just working on one application with two customers who have never asked about this. I tried to import API data to the application just to try it out. Weather data from yr.no and retrieval of one item from Brønnøysund went very well. I thought that when you registered new customers, it would have been nice if you only had to register a few letters to enter the necessary information.

I started this is a project in 1985 when I was employed by one of the companies. In Clarion 2.0 for DOS. They have been using this application for more than 25 years when they called me and asked if I could do a new Windows version. Then I had not programmed for many years, but decided to try.

Now that I’m over 70 and retired, this is becoming more of a hobby project, and I do not think I can defend the use of over $ 200 without being able to bill customers.

But in any case, I am very grateful for your contribution to help me, and for the time you have spent.

I just do not understand why it should be so difficult. Is it JSON.FromJSON that does not do a good enough job with queues? It is very easy with DIM inside square brackets.

Trond

I wish I could help more. I did include a text file with the various data structures. That might help.

Good luck,

Don

1 Like