If you’re a mobile developer, there’s a pretty good chance that you’ve used some kind of networking. Apps most often use a REST API, and usually it’s enough, as it allows fast and easy JSON based communication (here is a JSON object converter). One of the downsides is, however, that REST communication requires the client to […]
By Tamás Keller
In today’s world of iOS development, graphical interface editors, especially Storyboards, gain more and more popularity. It’s because they continously improve, are easy to grasp, and provide a lot of features to make our lives easier. Not to mention, they save us from a ton of coding. One of these key features is Auto Layout, […]
Introduction: What is Reactive Cocoa? What does functional and reactive mean, in terms of programming? Why is it useful, and generally a good practice? Getting started: How do I set up my project to start developing with RAC? Basics: Classes and methods used in RAC. General data flow representation. A small task: A short […]
About JSON in general
In today’s world, most of the mobile and web applications we write include some background activity with an API, like handling user info, or fetching data. Over 90% of the time (I didn’t look up the exact number, I’m sure you will forgive me) the servers respond with a JSON object containing the information we desire. If you’re unfamiliar with the structure of a JSON object, it’s definitely worth looking into. There are quite a few greatly designed tutorials on the topic, there’s one on W3Schools, for example.
Once we receive the API response, we generally want to pass this information to our business logic, and eventually to our viewcontrollers.
The most straightforward way would be to deserialize this string (it is essentially nothing more than textual data) into a valid JSON object. These objects are usually a hierarchy of dictionaries and arrays. However, accessing these values from the root object is a pain in the rear. It’s time-consuming, produces messy code, and it’s unsafe. A typo in our code while accessing a key will not produce any errors, since the keys are strings. Without the keen eyes of an experienced developer, who can spot a typo from a mile off, debugging these coding errors takes a lot longer than it should.