![]() |
Forum Index : Microcontroller and PC projects : Struggling to build some understanding of JSON
Author | Message | ||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3378 |
This may develop into an ongoing series of questions, but first, why doesn't this work? > list Dim As integer lBuff%(1000) Dim As string A,qt qt=Chr$(34) A="{"+qt+"a"+qt+":1,"+qt+"b"+qt+":2,"+qt+"c"+qt+":3,"+qt+"d"+qt+":4}" LongString append lBuff(),A Print A LongString print lBuff() Print JSON$(lBuff%(),"a") 'Print JSON$(lBuff(),"a"),JSON$(lBuff(),"b"),JSON$(lBuff(),"d") > run {"a":1,"b":2,"c":3,"d":4} {"a":1,"b":2,"c":3,"d":4} [12] Print JSON$(lBuff%(),"a") Error: Dimensions > This is running on an F4, "ARMmite MMBasic Version 5.05.10". PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3378 |
Here is another failure with JSON text snagged from the internet: [{"employees":[ {"name":"Shyam", "email":"shyamjaiswal@gmail.com"}, {"name":"Bob", "email":"bob32@gmail.com"}, {"name":"Jai", "email":"jai87@gmail.com"} ]}] > list Dim As integer lBuff%(1000) Dim As string A Open "employees.txt" For input As #1 Do While Not Eof(#1) A = Input$(250,#1) LongString append lBuff%(),A Loop Close #1 LongString print lBuff%() Print JSON$(lBuff%(),"employees[0].name") > run [{"employees":[ {"name":"Shyam", "email":"shyamjaiswal@gmail.com"}, {"name":"Bob", "email":"bob32@gmail.com"}, {"name":"Jai", "email":"jai87@gmail.com"} ]}] [14] Print JSON$(lBuff(),"employees[0].name") Error: Dimensions > I seem to be missing something fundamental. ~ Edited 2020-07-21 10:30 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
MikeO Senior Member ![]() Joined: 11/09/2011 Location: AustraliaPosts: 275 |
Hi Lisby, I did a bit of work recovering json with uMite that worked for me at the time. It didn't have much depth ability but could be the basis of some routine. Post is here Mike Codenquilts |
||||
disco4now![]() Guru ![]() Joined: 18/12/2014 Location: AustraliaPosts: 1003 |
Ran your first code on a Pi-cromite and its OK. Getting the same error as you on the F4 so might be a bug.Need to try on the H7 and see what happens. Gerry Latest F4 Latest H7 FotS |
||||
disco4now![]() Guru ![]() Joined: 18/12/2014 Location: AustraliaPosts: 1003 |
List Functions (also List Commands) does not mention JSON on the Armmite F4, so I think its not supported/implemented even though command is still recognised. list functions * + - / < << <= <> = =< => > >= >> \ ^ Abs( ACos( And As Asc( ASin( Atan2( Atn( Baudrate( Bin$( Bin2str$( Chr$( Cint( Cos( CtrlVal( Cwd$ Date$ DateTime$( Day$( Deg( Dir$( Distance( Else Eof( Epoch( Eval( Exp( Field$( Fix( For GetScanLine( GoSub GoTo GPS( Hex$( Inkey$ Input$( Instr( Int( LCase$( LCompare( Left$( Len( LGetStr$( LInStr( LLen( Loc( Lof( Log( Max( Mid$( Min( MM.Backup MM.Device$ MM.ErrMsg$ MM.Errno MM.FontHeight MM.FontWidth MM.HPos MM.HRes MM.I2C MM.Info$( MM.OneWire MM.Ver MM.VPos MM.VRes MM.Watchdog Mod MsgBox( Not Oct$( Or Peek( Pi Pin( Pixel( Port( Pos Pulsin( Rad( RGB( Right$( Rnd Rnd( Sgn( Sin( Space$( SPI( SPI2( Sqr( Step Str$( Str2bin( String$( Tab( Tan( TEMPR( Then Time$ Timer To Touch( UCase$( Until Val( While Xor Total of 123 functions and operators > list commands ADC Arc AutoSave BackLight Bezier Blit Box Case Case Else Chdir Circle Clear Close CLS Color Colour Const Continue CPU CtrlVal( DAC Data Date$ DefineFont DHT22 Dim Do Edit Else Else If ElseIf End End DefineFont End Function End If End Select End Sub EndIf Erase Error Exit Exit Do Exit For Exit Function Exit Sub FFT Files Font For Function GoSub GoTo GUI I2C I2C2 If Input IR IReturn KeyPad Kill LCD Let Line Line Input List Load Local LongString Loop Memory Mkdir Name New Next On OneWire Open Option Page Pause Pin( Pixel Play Poke Polygon Port( Print Pulse PWM RBox Read Rem Restore Return Rmdir Run Save Seek Select Case Servo SetPin SetTick SPI SPI2 Static Sub SYNC TEMPR START Text Time$ Timer Trace Triangle VAR WatchDog While WS2812 XModem Total of 119 commands > Latest F4 Latest H7 FotS |
||||
matherp Guru ![]() Joined: 11/12/2012 Location: United KingdomPosts: 10310 |
The command isn't recognised. The F4 is interpreting json$() as an array with incorrect dimensions, one of the issues with using the same type brackets in Basic for functions and arrays unlike C |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3378 |
Ahh, bummer. The F4 is so easy to use, and I have at least one every place I might sit and fiddle with MMBasic. The pi will work, but needs beefier power, and the CMM2 is relatively bulky. DOS MMBasic doesn't support JSON or longstrings. Thanks for looking. I was going to try the CMM2 today anyway. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3378 |
Thanks, Mike--that may serve as the basis for a cross-MMBasic version for me. I don't think I will need a lot of depth--although I probably will want a longstring version. I actually have similar code almost developed. ~ Edited 2020-07-21 22:07 by lizby PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
lizby Guru ![]() Joined: 17/05/2016 Location: United StatesPosts: 3378 |
Oops. CMM2 also lacks JSON$. PicoMite, Armmite F4, SensorKits, MMBasic Hardware, Games, etc. on fruitoftheshed |
||||
NPHighview![]() Senior Member ![]() Joined: 02/09/2020 Location: United StatesPosts: 203 |
Thanks for the great discussion about JSON, and for the tantalizing glimpse into the functions and commands available for the F4. I'm expecting delivery of a cmm2 in the next few days, and wonder whether "list functions" and "list commands" work in mmBasic on the cmm2, or if that's only available on the Armmite systems They don't in the DOS version of mmBasic. Fingers crossed! Especially looking for documentation of the FFTand all of the other MATH xxx routines... Edited 2020-09-20 05:26 by NPHighview Live in the Future. It's Just Starting Now! |
||||
TassyJim![]() Guru ![]() Joined: 07/08/2011 Location: AustraliaPosts: 6283 |
Note that JSDON is not available on the CMM2 LIST FUNCTIONS and LIST COMMANDS are available. You can always start reading the manuals while you wait for your delivery. Manual available from https://geoffg.net/maximite.html Jim VK7JH MMedit |
||||
NPHighview![]() Senior Member ![]() Joined: 02/09/2020 Location: United StatesPosts: 203 |
Thanks, Jim - I've been scouring the mmBasic manuals (DOS, cmm2, and F7) for mentions of the syntax "list functions" "list commands" or MATH xxx, and the forum as well. Limited joy; learning by seeing what you, Peter Mather, disconow, and others are doing, here and in Fruit of the Shed, seems to be my main hope at this point. The search function in the forum is a reasonable tool for this; it led me here while looking for documentation for the FFT routines. I'm not looking specifically at JSON, though recursion does intrigue me. I've written a deeply recursive memoized Ackermann function evaluator in mmBasic for DOS (contributed to Fruit of the Shed), and some other programs (like Conway's Life and a gravity game) that I use as my calibrators when picking up a new language. So far, mmBasic looks great. I really look forward to playing with the cmm2. Thanks for making this such a lively, dynamic ecosystem as well. This is frosting on the cake! - Steve "NPHighview" Johnson Edited 2020-09-20 11:59 by NPHighview Live in the Future. It's Just Starting Now! |
||||
![]() |
![]() |
The Back Shed's forum code is written, and hosted, in Australia. | © JAQ Software 2025 |