April 16, 2024, 04:07:11 PM

News:

IonicWind Snippit Manager 2.xx Released!  Install it on a memory stick and take it with you!  With or without IWBasic!


JSON

Started by markem, May 23, 2017, 05:59:49 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

markem

I have seen the XML class that Larry did. I was wondering if anyone has thought of doing the two major JSON functions (JSON_ENCODE and JSON_DECODE)?

My reasoning is that Javascript and PHP both use similar functions to be able to quickly and easily convert between JSON and regular variables/arrays. I just bought IWBasic and it isn't that I NEED it - I just wondered if anyone had done this. Later on I will be looking at making these two functions myself (like six to eight months from now).

The layout (as I see it) would be a structure which looks like this.  (Please remember I just got IWBasic so this is pseudo code):

Class JSON_CLASS
   dim var as string,
   dim ary as array,   ' Do you say just "array" or is it "string array"?
end class

A variable would be dim'd as the JSON_CLASS and as the incoming string is parsed either var or ary is filled. But if you can't have arrays in a class (or structure or type) then I'd have to think of some other way to do this.  :-/

I've never parsed a JSON file before but it would be a good thing to be able to do. :-)

Ideas?  Suggestions? :-)

Andy

I think to begin with, you would need to make a user defined variable type (UDT).

Here is an example:

TYPE phonerecord
         DEF Name:STRING
         DEF Age:INT
         DEF Phone[20]:ISTRING
ENDTYPE

DEF Rec:phonerecord
Rec.Name = "Joe Smith"
Rec.Age = 35
Rec.Phone = "555-555-1212"

Have a read of this example and have a play around with it.

Andy.
Day after day, day after day, we struck nor breath nor motion, as idle as a painted ship upon a painted ocean.

markem

@andy: First - thanks for clearing up what word was the right one to use (ie: TYPE).

I was thinking that because JSON (like XML) is very generic in nature, that you would have to keep everything separate.  More like so:

TYPE JSON_RECORD
     DEF id:STRING
     DEF value[]:STRING
     DEF child:POINTER
     DEF sibling:POINTER
ENDTYPE

The "id" is the name of the variable.
The "value" are the values found (either single or array so it has to be an array).
The "child" variable points to the next entry.
The "sibling" variable is used if the array is a two dimensional array (or three, four, or whatever)

In this way you can build out the incoming information.

Still thinking about this. Got IWBasic installed, got Snippet Manager installed, got IWB+ installed, got Button Designer installed.

Now I just have to feel well enough to actually do some programming and reading up on how the functions for IWBasic. I think I forgot to get the manual with all of the functions listed in it. I probably need to go buy that too. :-)

Anway - thanks andy! :-)

LarryMc

Quote from: markem on May 24, 2017, 07:41:33 AM
I think I forgot to get the manual with all of the functions listed in it. I probably need to go buy that too. :-)

You don't have to buy any manuals for the software you bought.
LarryMc
Larry McCaughn :)
Author of IWB+, Custom Button Designer library, Custom Chart Designer library, Snippet Manager, IWGrid control library, LM_Image control library

markem

@Larry : Heh - too late! :-) Think of it as helping to support everything. :-) I have a few dollars I can spend and this is a great way to do that.

I also do this for FastStone Screen capture program. It is a fantastic screen capture program I was introduced to back in 2009. I think I've bought something like ten or fifteen copies to encourage the guy to continue to improve the program. :-)