I'm finally getting around to playing with B4A more lately (came from years and years of VB 3-6) and although it's definitely easier than pure Java/Android programming, which I looked into (using Eclipse), I'm just having the hardest time with simple stuff. :BangHead:
It took me hours just to finally figure out how to 'clear' the screen when showing and hiding different views. After hours of searching and barking up the wrong tree, I finally stumbled on an errant thread here that happened to mention it. How embarrassing!
Anyhoo.... The app I'm working on now is kind of just an experiment for me to learn how to use B4A better, and I'm definitely understanding some things better than before, but I am having a problem with JSON.
It took me a while, but I finally figured out how to extract info from a JSON file located on a web server. Now I am trying to start getting my app to store information. I was initially going to use XML, but figured since I'm already using JSON a bit, why not just use that?
Below is a proposed file I would like my app to use. I would prefer it to be located on the SD card so that settings can be backed up and retained.
Here is the file:
It took me lots of experimenting to come up with this JSON file. I finally got it correct after using online validators, but I can't for the life of me figure out how to do two simple things:
Save info to it and retrieve info from it! I'm not even sure how to start because I'm not sure if I can include a "skeleton" config file with my app in the APK or if I would need to generate it on first run, and if so, how? Can something with this kind of structure easily be created in code? Or does one usually somehow include a copy of the file with the APK and copy it to the device's SD card through code?
In case it's not obvious, I need to be able to get and set app options (AppSettings), which are all just single values. I also want to be able to get and set "receiver" (ip address and name), "macro" (name and text/value), and "favorite" (name and text/value). These last 3 settings should be arrays (*I think*), in that there could be none or many of these in the JSON file and it needs to be able to add and remove entries, such as for "receiver". I'm pretty sure I can work THAT part out once I figure out the basics of manipulating the data in the file, but I can't wrap my brain around objects, maps, arrays and values and how they all relate to different elements in a JSON file.
I've looked through the tutorials, help file, forum, etc, and I just can't figure it out. I'd appreciate any help anyone could offer me. :sign0104: I was starting to have fun with my little project because I've always enjoyed programming but now I am just getting frustrated. (I used to spend almost all of my free time programming in VB6 until I started a family and got a bigger "job" about 6 years ago.) Now I've spent the whole day messing with this and I haven't gotten anywhere.
As much as I hated to come on the forum begging for help, I will say that this is definitely one of the most helpful forums I've come across, and it's much appreciated for something like B4A. While there is extensive help and samples, it just doesn't cover everything in enough detail for me to figure it all out.
It took me hours just to finally figure out how to 'clear' the screen when showing and hiding different views. After hours of searching and barking up the wrong tree, I finally stumbled on an errant thread here that happened to mention it. How embarrassing!
Anyhoo.... The app I'm working on now is kind of just an experiment for me to learn how to use B4A better, and I'm definitely understanding some things better than before, but I am having a problem with JSON.
It took me a while, but I finally figured out how to extract info from a JSON file located on a web server. Now I am trying to start getting my app to store information. I was initially going to use XML, but figured since I'm already using JSON a bit, why not just use that?
Below is a proposed file I would like my app to use. I would prefer it to be located on the SD card so that settings can be backed up and retained.
Here is the file:
B4X:
{
"receiver": [
{
"ip": "0",
"name": "BASEMENT"
}
],
"macro": [
{
"name": "Test",
"command": "up"
}
],
"favorite": [
{
"name": "Test",
"channel": "26.2"
}
],
"AppSettings": {
"HasBeenSetup": 1,
"NumRuns": 1,
"LastRemote": 1,
"LastReceiver": "BASEMENT",
"StartOn": "Setup",
"Haptic": 1
}
}
It took me lots of experimenting to come up with this JSON file. I finally got it correct after using online validators, but I can't for the life of me figure out how to do two simple things:
Save info to it and retrieve info from it! I'm not even sure how to start because I'm not sure if I can include a "skeleton" config file with my app in the APK or if I would need to generate it on first run, and if so, how? Can something with this kind of structure easily be created in code? Or does one usually somehow include a copy of the file with the APK and copy it to the device's SD card through code?
In case it's not obvious, I need to be able to get and set app options (AppSettings), which are all just single values. I also want to be able to get and set "receiver" (ip address and name), "macro" (name and text/value), and "favorite" (name and text/value). These last 3 settings should be arrays (*I think*), in that there could be none or many of these in the JSON file and it needs to be able to add and remove entries, such as for "receiver". I'm pretty sure I can work THAT part out once I figure out the basics of manipulating the data in the file, but I can't wrap my brain around objects, maps, arrays and values and how they all relate to different elements in a JSON file.
I've looked through the tutorials, help file, forum, etc, and I just can't figure it out. I'd appreciate any help anyone could offer me. :sign0104: I was starting to have fun with my little project because I've always enjoyed programming but now I am just getting frustrated. (I used to spend almost all of my free time programming in VB6 until I started a family and got a bigger "job" about 6 years ago.) Now I've spent the whole day messing with this and I haven't gotten anywhere.
As much as I hated to come on the forum begging for help, I will say that this is definitely one of the most helpful forums I've come across, and it's much appreciated for something like B4A. While there is extensive help and samples, it just doesn't cover everything in enough detail for me to figure it all out.