Article Preview
Buy Now
COLUMN
JSON Dictionary
Converting Dictionaries to JSON
Issue: 14.5 (September/October 2016)
Author: Marc Zeedar
Author Bio: Marc taught himself programming in high school when he bought his first computer but had no money for software. He's had fun learning ever since.
Article Description: No description available.
Article Length (in bytes): 17,556
Starting Page Number: 82
Article Number: 14508
Resource File(s):
project14508.zip Updated: 2016-09-01 11:29:50
Related Link(s): None
Excerpt of article text...
If you haven't tried using JSON in Xojo, you may be missing a handy tool. JSON is a plain-text data format that is popular on the web. It's similar to XML in some ways, but is much simpler and easier to create and parse.
Since JSON can store data in a manner similar to a Xojo
dictionary
—key-value pairs—JSON is terrific for recording things like your application's preferences or simple data structures. Essentially, you can take a JSON object filled with data and with one command, convert it to a string to save to disk. Naturally, you can also do the reverse.However, when I first explored JSON, I was disappointed to see that while it's
similar to adictionary
, it's not the same. And since it's a different kind of object, if you're already using dictionaries, you have to change them toJSONitem
objects and revise a bunch of code.I love dictionaries and use them in almost every Xojo project I create. Changing all that code to JSON seemed like a lot of work. A better way would be to make some routines to convert a
dictionary
to aJSONitem
and vice versa.A Look at JSON
Before we get to my conversion routine, let's explore the JSON data format and see how JSON works in Xojo. In Xojo, you work with JSON by creating
JSONitem
objects. The object has methods to add and delete data, as well as properties that control how the string version of the JSON data is formatted.
...End of Excerpt. Please purchase the magazine to read the full article.