Simple array loop problems

Recurrent H/W and software problems
Post Reply
mac_che@hotmail.com
Posts: 7
Joined: Sat Feb 05, 2022 10:11 am
Been thanked: 2 times

Simple array loop problems

Post by mac_che@hotmail.com »

I want to display 10 numeric and text values from a json file
TP=10
dim Mag(TP) : dim Loc$(TP)

' Read event history from file into array.

for lcnt = 1 to TP
Mag = val(json$(result$,"properties.mag[" + str$(lcnt) + "]" )) <<<This is a number (e.g 5.1.3.2 etc)
Mag(lcnt) = Mag

Loc$ = json$(result$,"properties.flynn_region[" + str$(lcnt) + "]") <<<This is text (E.g Hawaii, Hawaii)
Loc$(lcnt) = Loc$
next lcnt

tft.text.draw str$(Mag(1)),100,90,3 <<Works
tft.text.draw str$(Loc$(1)),100,100,3 << Does not work (Type mismatch)
Json:

"type": "Feature",
"id": "20220218_0000088",
"properties": {
"lastupdate": "2022-02-18T13:16:00.0Z",
"magtype": "mb",
"evtype": "ke",
"lon": -25.39,
"auth": "GFZ",
"lat": -56.67,
"depth": 15.0,
"unid": "20220218_0000088",
"mag": 4.9,
"time": "2022-02-18T02:29:31.9Z",
"source_id": "1098163",
"source_catalog": "EMSC-RTS",
"flynn_region": "SOUTH SANDWICH ISLANDS REGION"
}
How can I display the values of Loc$(1) (2) etc?
AndyGadget
Posts: 222
Joined: Mon Feb 15, 2021 1:44 pm
Has thanked: 119 times
Been thanked: 132 times

Re: Simple array loop problems

Post by AndyGadget »

A bit late to look at your code in detail now, but this may be of help :
[Local Link Removed for Guests]
The Annex JSON parser doesn't quite work as you'd expect.
mac_che@hotmail.com
Posts: 7
Joined: Sat Feb 05, 2022 10:11 am
Been thanked: 2 times

Re: Simple array loop problems

Post by mac_che@hotmail.com »

Hi Andy,

i found that post as well.
I guess Magnitude is not a problem since that's a number on it's own or it's a "one word" value (eg. 5.2).
where Location can be Sicily, Italy for example, I really don't know what the difference is otherwise. (Based on the type mismatch part)
tft.text.draw str$(Mag(1)),100,90,3 <<Works
tft.text.draw str$(Loc$(1)),100,100,3 << Does not work (Type mismatch)
I also have the feeling that writing to a file is more stable than using the json parser. Everytime I save the code whil editing (after running the code) the ESP reboots. It works perfectly afterwards without crashing but doesn't feels ok. Did you experienced that as well?
bugs
Posts: 142
Joined: Mon Feb 08, 2021 10:10 pm
Location: Scotland
Has thanked: 44 times
Been thanked: 50 times

Re: Simple array loop problems

Post by bugs »

Hi,

First - I know zero about json.
But str$("Italy") will give a syntax error for obvious reasons and so will str$( loc$) and str$(loc$(1)).
Str$ is only used to convert a number to a string. Just omit it and print loc$(n).

Hope that makes sense...
Post Reply