Discussion Forums  >  Plugins, Customizing, Source Code

Replies: 3    Views: 52

Ed Goodall
Fusion Technology
Profile
Posts: 422
Reg: Oct 01, 2011
Wiltshire, UK
12,320
09/05/14 03:09 PM (9 years ago)

Ultimate Screen Creator Screen Change depending on JSON

Hi Now I have managed to get a JSON response from my MSSQL server, I need to be able to show different information on the USC screen depending on the response. Basically, if stageOne comes back as Yes, I need a green tick to appear as an image (already have the image as a png.) and if No, I need a red cross to appear instead, again already a png. So, how can I show different things on the screen depending on the JSON that comes back from my php script? Thanks Ed
 
chris1
Code is Art
Profile
Posts: 3862
Reg: Aug 10, 2012
Austin, TX
50,120
like
09/05/14 05:03 PM (9 years ago)
wow, that's a tall order, actually. The way the USC is created, you will need to do one of 2 things: 1) Decipher the JSON structure necessary for the USC screen. Build a screen with the layout you want, and take note of the difference between having it show one image or the other. A word of warning: the JSON is c-r-a-z-y for that screen. It won't even look like JSON. In fact, it's not - at least not until the plugin does it's magic, converting the mess into JSON. The reason is due to the way the Buzztouch backend handles child items and some other stuff. I had to write my own format for data (I'd call it 'Chris1 Object Notation', but then it would just be a CON!). Anyway, the difference is that all the double quotes and brackets are replaced with other character sequences, like ##. Then, the plugin searches for those and replaces them with the standard JSON equivalent. Once you figure this out, you can always have your server spit out standard JSON for the same key names, etc and the plugin will read it just fine. It won't convert any CON into JSON because there is no CON to worry about. Instead it will just use the JSON as normal. But, the tricky part is sifting through all the code to figure out the multitude of JSON key names you'll need to worry about. Also, you'll lose the ability to make changes via the control panel to the layout. 2) The other option is to write your own code to query a script, grab the data, and do something with the result. This is probably the easier of the two methods, but still requires knowing your way around code. You won't be able to use the BT_downloader class to do that, since that class is already used by the plugin and it can only be used once in a plugin. So, you'll need to write your own code for handling downloads. One option is to just copy the BT_downloader into new class files (like EG_downloader), but you'll have to know how to make your own protocol/delegate methods, call them and implement them. There's other ways of going about downloading a file and parsing the results too, that don't require a protocol. But you have to be careful about handling it all on the right thread and making sure errors are safely accounted for. As I said, it's a tough order either way unless you know what you are doing.
 
Ed Goodall
Fusion Technology
Profile
Posts: 422
Reg: Oct 01, 2011
Wiltshire, UK
12,320
like
09/05/14 11:08 PM (9 years ago)
Do you think it would be easier just to display an Alert View with preset text depending on the result then? Because that would be ok
 
Niraj
buzztouch Evangelist
Profile
Posts: 2943
Reg: Jul 11, 2012
Cerritos
37,930
like
09/07/14 07:23 AM (9 years ago)
Let us know how you get it solved, Ed.
 

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.