Special

Introducing the “Welcome to Xojo” Bundle!

New to Xojo and looking for guidance? We've put together a terrific bundle to welcome you! Xojo Bundle

This bundle includes six back issues of the magazine -- all of year 14 in printed book and digital formats -- plus a one-year subscription so you'll be learning all about Xojo for the next year. It's the perfect way to get started programming with Xojo. And you save as much as $35 over the non-bundle price!

This offer is only available for a limited time as supplies are limited, so hurry today and order this special bundle before the offer goes away!

Article Preview


Buy Now

Issue 14.5 ('Keyboard Shortcuts')
Instant purchase and download via GumRoad!

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):

Download Icon 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 a dictionary, 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 to JSONitem 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 a JSONitem 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.