B4J Question JSON to build a menu bar in B4J

jtbandmusic

New Member
Hello!
An eon ago (maybe 1990 or so) I wrote a program I was proud of, and
after a career change, stroke, retirement, etc., I decided to rewrite it.
Everthing has been fine until I got to recreating the menu. Instead of
the VB6 buider I need to enter a JSON string in the menubar to create the menu.
I've never seen JSON, and this doesn't even look like computer code.

I have searched for JSON which might form a menu, but examples are hard
to find. What I need is going to look a lot like the text below, with
the indented lines beginning {Text: which will become the menu titles
and the column on the left margin producing the menu items below.

I'm hoping some smart, helpful person will correct the puncuation and
send send this back in valid JSON string form.

Thanks!
John Thompson
 

Attachments

  • Menubar Letter.txt
    1.3 KB · Views: 61

teddybear

Well-Known Member
Licensed User
B4X:
[
  {
    "Text": "_File",
    "Children": [
      "_New Show",
      "_Save",
      "Save As",
      "_Load",
      "_Print",
      "_Print Page",
      "-",
      "_Close"
    ]
  },
  {
    "Text": "_Panels",
    "Children": [
      "_Show",
      "_Page",
      "_Linear",
      "_Block",
      "_FTL",
      "_Route",
      "_Selection",
      "_Props",
      "_Drawing"
    ]
  },
  {
    "Text": "_View",
    "Children": [
      "_Grid & Snap",
      "_Menber",
      "_Field",
      "_Ghost & Hide",
      "_Height",
      "_Zoom",
      "_Center",
      "Path Lines"
    ]
  },
  {
    "Text": "_Roster",
    "Children": [
      "_Create Roster",
      "_Member Names",
      "_Help",
      "_About Hugo"
    ]
  }
]

You can check valid json using json-validator
 
Last edited:
Upvote 0

rraswisak

Active Member
Licensed User
One of JSON syntax rule: must have pairs of name and value:

B4X:
[
  {
    "Text": "_File",
    "Children": [
      { "Name": "new_show", "Text": "_New Show" },
      { "Name": "save", "Text": "_Save" },
      { "Name": "save_as", "Text": "Save As" },
      { "Name": "load", "Text": "_Load" },
      { "Name": "print", "Text": "_Print" },
      { "Name": "print_page", "Text": "_Print Page" },
      { "Name": "separator", "Text": "-" },
      { "Name": "close", "Text": "_Close" }
    ]
  },
  {
    "Text": "_Panels",
    "Children": [
      { "Name": "show", "Text": "_Show" },
      { "Name": "page", "Text": "_Page" },
      { "Name": "linear", "Text": "_Linear" },
      { "Name": "block", "Text": "_Block" },
      { "Name": "ftl", "Text": "_FTL" },
      { "Name": "route", "Text": "_Route" },
      { "Name": "selection", "Text": "_Selection" },
      { "Name": "props", "Text": "_Props" },
      { "Name": "drawing", "Text": "_Drawing" }
    ]
  },
  {
    "Text": "_View",
    "Children": [
      { "Name": "grid_snap", "Text": "_Grid & Snap" },
      { "Name": "member", "Text": "_Menber" },
      { "Name": "field", "Text": "_Field" },
      { "Name": "ghost_hide", "Text": "_Ghost & Hide" },
      { "Name": "height", "Text": "_Height" },
      { "Name": "zoom", "Text": "_Zoom" },
      { "Name": "center", "Text": "_Center" },
      { "Name": "path_line", "Text": "Path Lines" }
    ]
  },
  {
    "Text": "_Roster",
    "Children": [
      { "Name": "create_rooster", "Text": "_Create Roster" },
      { "Name": "member_names", "Text": "_Member Names" },
      { "Name": "help", "Text": "_Help" },
      { "Name": "about", "Text": "_About Hugo" }
    ]
  }
]

This is how to read the data:
B4X:
Dim parser As JSONParser 
parser.Initialize(<text>) '<text> is json data
Dim jRoot As List = parser.NextArray 
For Each coljRoot As Map In jRoot 
 Dim Text As String = coljRoot.Get("Text") 
 Dim Children As List = coljRoot.Get("Children") 
 For Each colChildren As Map In Children 
  Dim Text As String = colChildren.Get("Text") 
  Dim Name As String = colChildren.Get("Name") 
 Next 
Next
 
Upvote 0

Chris2

Active Member
Licensed User
 
Upvote 0

jtbandmusic

New Member
Original poster here. I just copied HoneyBear's JSON into my program's menu textbox; it works perfectly!
Thanks everyone, and especially HoneyBear.
Thanks again;
John Thompson
 
Upvote 0

JohnJ

Member
Licensed User
Longtime User
Have a look at this.

 
Upvote 0
Top