Discussion Forums  >  Config Data, JSON, App Refresh

Replies: 19    Views: 142

GoNorthWest
buzztouch Evangelist
Profile
Posts: 8197
Reg: Jun 24, 2011
Oro Valley, AZ
1,000,000
02/10/16 10:25 AM (3 years ago)

Creating Menu Lists Via JSON

Hello,

I'm trying to create nested menu lists via JSON, using the Simple Menu List's data URL capability. Basically, I want to query a SQL database and generate a set of menus. It would look something like this:

* Jeep
CJ
CJ Info (Custom URL)
Wrangler
Wrangler Info (Custom URL)
* Toyota
Carolla
Carolla Info (Custom URL)
Sienna
Sienna Info (Custom URL)

Makes sense? The query would get a list of makes and create a menu list from that. Then each make would have a linked menu list of various models, that then link to a web page about information related to it.

I've figured out the JSON for the initial (make) list items, and it looks like this:

{"childItems":[{
"itemId":"99999",
"itemType":"BT_menuItem",
"loadScreenWithItemId":"Jeep_List",
"titleText":"Jeep"
}]}

From this, I can populate the initial list with tons of entries. However, I'm completely stuck on how to create the list that get's generated when you hit "Jeep." I need it to link to a BT_screen_menuListSimple. Simply cannot figure out how to do this!

Remember...this is all being driven by the contents merged from a data URL!

Can anybody help?

Thanks!

Mark
 
fusionsch
I hate code!
Profile
Posts: 508
Reg: Dec 28, 2010
Montreux Switze...
11,530
like
02/10/16 12:06 PM (3 years ago)
Hi Mark,

I guess you can do it with loadScreenObject. I've never done it with Simple Menu, but I use it extensively in all my apps, as simple text files as well as queries to PHP creating JSON files on-the-fly.

Have you ever used loadScreenObject? If not, maybe I can try to create a syntax sample for you...

Cheers

Jack
 
GoNorthWest
buzztouch Evangelist
Profile
Posts: 8197
Reg: Jun 24, 2011
Oro Valley, AZ
1,000,000
like
02/10/16 12:12 PM (3 years ago)
Hi Jack,

I think I've read that advice somewhere as well. If you have a syntax example that I can plug in to understand how it works, that would be awesome!

Mark
 
fusionsch
I hate code!
Profile
Posts: 508
Reg: Dec 28, 2010
Montreux Switze...
11,530
like
02/10/16 01:09 PM (3 years ago)
Hi Mark,

Just to have a look: http://www.fusions.ch/iphone-apps/iNaxos/tips/tips.txt

It's not a sample with Simple Menu, but maybe you'll understand the logic?

Anyway, I can create a sample with Simple Menu nesting Simple Menu... but only tomorrow!

Cheers

Jack
 
GoNorthWest
buzztouch Evangelist
Profile
Posts: 8197
Reg: Jun 24, 2011
Oro Valley, AZ
1,000,000
like
02/10/16 02:17 PM (3 years ago)
That looks promising! Let me digest it a bit tonight and I'll let you know.

Thanks!

Mark
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
02/10/16 02:54 PM (3 years ago)
Wow Jack, serious json going on. Impressive! :)

Mark; don't forget the WB_addOns. Maybe not exactly what you want or need, but a lot of php/mysql scripting that is close, and (relatively) easily adaptable.

https://www.marianasgps.com/public/index.php

Cheers!

-- Smug
 
GoNorthWest
buzztouch Evangelist
Profile
Posts: 8197
Reg: Jun 24, 2011
Oro Valley, AZ
1,000,000
like
02/10/16 03:07 PM (3 years ago)
Hi Smug,

Thanks for the pointer! Susan mentioned it to me as well yesterday, and I sorta dismissed it because this app isn't self hosted...but, makes sense to read through the code and see what's going on.

Thanks!

Mark
 
Dusko
Veteran developer
Profile
Posts: 998
Reg: Oct 13, 2012
Beograd
22,680
like
02/10/16 03:35 PM (3 years ago)
First have a look at what the plugin needs to have as input data. In this case, let it be the Menu Simple plugin. To see its JSON, go here:

https://www.buzztouch.com/plugins/plugin.php?pid=334A4B840178A021CF61919

and find the code needed in the very end of the plugin description. I'll reproduce it for the sake of clarity:

{
"itemId":"1111",
"itemType":"BT_screen_menuListSimple",
"navBarTitleText":"My Simple Menu",
"childItems":[
{
"itemId":"menu_1",
"itemType":"BT_menuItem",
"titleText":"This is row 1",
"loadScreenWithItemId":"1234"
},
{
"itemId":"menu_2",
"itemType":"BT_menuItem",
"titleText":"This is row two",
"loadScreenWithItemId":"5678"
}
]
}

Then make a file on server in the following way:

Copy the above text into a text editor and change all appearances of " into \". You should have something like this:

{
\"itemId\":\"1111\",
\"itemType\":\"BT_screen_menuListSimple\",
\"navBarTitleText\":\"My Simple Menu\",
\"childItems\":[
{
\"itemId\":\"menu_1\",
\"itemType\":\"BT_menuItem\",
\"titleText\":\"This is row 1\",
\"loadScreenWithItemId\":\"1234\"
},
{
\"itemId\":\"menu_2\",
\"itemType\":\"BT_menuItem\",
\"titleText\":\"This is row two\",
\"loadScreenWithItemId\":\"5678\"
}
]
}

Then go to the server, create a new php file and copy the text above into it. Then change is slightly so that you have the following text:

<?php
$a = "
{
\"itemId\":\"1111\",
\"itemType\":\"BT_screen_menuListSimple\",
\"navBarTitleText\":\"My Simple Menu\",
\"childItems\":[
{
\"itemId\":\"menu_1\",
\"itemType\":\"BT_menuItem\",
\"titleText\":\"This is row 1\",
\"loadScreenWithItemId\":\"1234\"
},
{
\"itemId\":\"menu_2\",
\"itemType\":\"BT_menuItem\",
\"titleText\":\"This is row two\",
\"loadScreenWithItemId\":\"5678\"
}
]
}";
echo $a
?>

This is a fully functional PHP program, so execute it. You can see it in action from here:

http://bestappbuilders.com/myjsonexample/

This is what you will get in the browser:

{ "itemId":"1111", "itemType":"BT_screen_menuListSimple", "navBarTitleText":"My Simple Menu", "childItems":[ { "itemId":"menu_1", "itemType":"BT_menuItem", "titleText":"This is row 1", "loadScreenWithItemId":"1234" }, { "itemId":"menu_2", "itemType":"BT_menuItem", "titleText":"This is row two", "loadScreenWithItemId":"5678" } ] }

This is exactly what the BT plugin such as Menu Simple needs. Now create a new app or create a new screen in the existing app of yours and put the address into the arrowScreen Data URL in the control panel in the plugin. Save it and execute the app -- you will get a Menu Simple with two option

This is row 1
This is row two

You can tap on this and it will react properly, however, most likely you will get the Plugin Missing screen if you haven't compiled anything in the app in the first place.

There you go -- your first PHP to JSON to Buzztouch path!

This can be as complicated as you want it to be. The PHP can become very complex very quickly if you access MySQL databases; JSON here is very simple, but in real life it can quickly get of hand, with dozens of parameters, and, finally, BT can be very complex on its own. If it is not Menu Simple... well... complicated would be a word to describe all this.
 
Dusko
Veteran developer
Profile
Posts: 998
Reg: Oct 13, 2012
Beograd
22,680
like
02/10/16 03:43 PM (3 years ago)
 
GoNorthWest
buzztouch Evangelist
Profile
Posts: 8197
Reg: Jun 24, 2011
Oro Valley, AZ
1,000,000
like
02/10/16 03:58 PM (3 years ago)
Hi Dusko,

Good stuff...thanks!

Let's extend this a bit...

I get the part where you have a menu list that has the following two rows:

This is row 1
This is row two

And, indeed, if I tap on that, it'll complain about a missing plugin.

Where I'm having difficulty is understanding how to format the JSON so that when I tap on "This is row 1" it loads another menu list. For a simple menu list itself, I understand the concept of the childItems and how to populate each row. But, I can't figure out how to tab and have it lead to another menu! I suspect it has something to do with loadObject instead of loadItem.

Thanks!

Mark
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
02/10/16 06:54 PM (3 years ago)
There are a lot of good examples in Jacks (MySPS) Json... do a search for his instances of loadScreenObject.

Also, I've always meant to finish, but never did, a little tutorial on LSO. But here is what I have so far:

https://www.marianasgps.com/public/loadScreenObjectTut.pdf

Cheers!

-- Smug
 
GoNorthWest
buzztouch Evangelist
Profile
Posts: 8197
Reg: Jun 24, 2011
Oro Valley, AZ
1,000,000
like
02/10/16 08:36 PM (3 years ago)
Ahh...that's some good stuff! With all this, I should be able to get things in order. Thanks!

Mark
 
GoNorthWest
buzztouch Evangelist
Profile
Posts: 8197
Reg: Jun 24, 2011
Oro Valley, AZ
1,000,000
like
02/10/16 11:54 PM (3 years ago)
Best partially completed tutorial ever! Based on the very first example you gave in the PDF, I was able to figure out how to get done what I needed! Took me a while to get the brackets matched up correctly, but when I did, it fell into place. Here's the code:

{
"childItems": [
{
"itemId": "Jeep",
"itemType": "BT_menuItem",
"titleText": "Jeep",
"loadScreenObject": {
"itemID": "Jeep_Menu",
"itemType": "BT_screen_menuListSimple",
"itemNickname": "Jeeps",
"navBarTitleText": "Jeeps",
"childItems": [
{
"itemId": "CJ",
"itemType": "BT_menuItem",
"titleText": "CJ",
"loadScreenObject": {
"itemID": "CJ_Info",
"itemType": "BT_screen_customURL",
"dataURL": "http://www.google.com"
}
}, {
"itemId": "Wrangler",
"itemType": "BT_menuItem",
"titleText": "Wrangler",
"loadScreenObject": {
"itemID": "Wrangler_Info",
"itemType": "BT_screen_customURL",
"dataURL": "http://www.google.com" }
}]
}
},
{
"itemId": "Toyota",
"itemType": "BT_menuItem",
"titleText": "Toyota"
"loadScreenObject": {
"itemID": "Toyota_Menu",
"itemType": "BT_screen_menuListSimple",
"itemNickname": "Toyota",
"navBarTitleText": "Toyota",
"childItems": [
{
"itemId": "Carolla",
"itemType": "BT_menuItem",
"titleText": "Carolla",
"loadScreenObject": {
"itemID": "Carolla_Info",
"itemType": "BT_screen_customURL",
"dataURL": "http://www.google.com"
}
}, {
"itemId": "Sienna",
"itemType": "BT_menuItem",
"titleText": "Sienna",
"loadScreenObject": {
"itemID": "Sienna_Info",
"itemType": "BT_screen_customURL",
"dataURL": "http://www.google.com" }
}]
}
}]
}

I'm thinking there's a more elegant way to do this..will be giving that some thought!

Thanks, Smug! You rock!

Mark
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
02/10/16 11:59 PM (3 years ago)
I'm not sure about elegance, lol! But as far as I know, you can cascade as many times as you want, although it could get a little muddled.

You can also break them up a little, if the cascading starts to get too deep... just create a 'dataURL' or 'localFilename' for the 'next cascade' and start a new document or script...

Those concepts are used in the WB_addOn scripts... the dataURL is a different script that provides childItem or LSO data...

Cheers!

-- Smug
 
GoNorthWest
buzztouch Evangelist
Profile
Posts: 8197
Reg: Jun 24, 2011
Oro Valley, AZ
1,000,000
like
02/11/16 12:03 AM (3 years ago)
I shouldn't have to cascade more than this, but I'm thinking a new script for each menu level might tidy things up a bit. Gonna sleep on it and see what I think in the morning.

Thanks again, to you and everybody who commented, for the help!

Mark
 
fusionsch
I hate code!
Profile
Posts: 508
Reg: Dec 28, 2010
Montreux Switze...
11,530
like
02/11/16 01:48 AM (3 years ago)
You got it, Mark, your sample is almost perfect!

Just one error: a missing comma on the line where you have the 2nd occurrence of the word Toyota.

Add this comma and it works perfectly (I've just tested it in an app under development)!

@smug: thanks for the compliment! I have some 'cascading JSONs' that are much more complicated if you wish (but you'll need Aspirine)... I'm still a noob with code but loadScreenObjecting is one of my favorite games...

Cheers

Jack
 
GoNorthWest
buzztouch Evangelist
Profile
Posts: 8197
Reg: Jun 24, 2011
Oro Valley, AZ
1,000,000
like
02/11/16 09:07 AM (3 years ago)
Hi Jack,

Thanks for the help and the feedback! I added the comma and indeed it validates as good JSON. I'm almost positive this same code is working in Xcode without the comma, which is strange. Either way, I'll make sure to have them all in the future.

Thanks again for the help!

Mark
 
fusionsch
I hate code!
Profile
Posts: 508
Reg: Dec 28, 2010
Montreux Switze...
11,530
like
02/11/16 09:47 AM (3 years ago)
Hi Mark,

I've seen that sometimes this kind of tiny error doesn't mess up things in Xcode (or even in the app)... but who knows? I prefer to be cautious...

Happy to have been able to help!

Cheers

Jack
 
SmugWimp
Smugger than thou...
Profile
Posts: 6316
Reg: Nov 07, 2012
Tamuning, GU
81,410
like
02/11/16 03:52 PM (3 years ago)
What iOS allows, Android destroys.

Cheers!

-- Smug
 
Niraj Shah
buzztouch Evangelist
Profile
Posts: 2937
Reg: Jul 11, 2012
Cerritos
37,870
like
03/06/16 10:16 AM (3 years ago)
Classic statement by Smug right there!

by the way, loadScreenObject is the magic that allows for dynamic data from a dynamic Database-PHP server or static file server.

-- Niraj
 

Login + Screen Name Required to Post

pointerLogin to participate so you can start earning points. Once you're logged in (and have a screen name entered in your profile), you can subscribe to topics, follow users, and start learning how to make apps like the pros.