patpitchaya - Fotolia
The standard package communication format is JSON packets sent through RESTful services. There are other ways to send data such as SOAP, OData and XML, but JSON is the default standard. A JSON API can be easily consumed by Web, iOS, Windows and Android projects.
In this article, you will learn how to connect to JSON APIs in an Android project, which frameworks to use and how to connect to specific API frameworks Google has developed to make it easier to be an Android developer.
Connecting to JSON APIs
The good news is that Google has implemented JSON support directly into Android. This is accomplished with the android.util.JsonReader Object. Google provides a complete example of how the framework works.
The bottom line is that JSON applies to the following two methods:
- Array handling methods: beginArray(), endArray(), hasNext()
- Object handling methods: beginObject(), endObject(), hasNext()
The goal is to load a JSON packet, examine the contents of the object and then do something with the data.
JSON frameworks to use with Android projects
There are a large number of frameworks that make it easier work with JSON APIs. Here are some good examples:
- RestLet: build, test and run APIs for projects.
- Spring for Android: quickly add APIs built with Spring framework.
- Volley Framework: an easy to implement framework for JSON.
- GSon: make it easy to add rich JSON functionality.
- Jackson: another lightweight, fast JSON framework.
Experiment with these frameworks to see which works best for you and your team.
Additional frameworks Google supplies for Android
Google wants to make it easier to create solutions for developers. To do this, they have developed a series of APIs that support this goal. These APIs fall into three categories: develop, engage and earn. Here are specific APIs that teams should use:
- Analytics: track everything about how users interact with an app.
- Maps: arguably the most successful API of all time gives developers the opportunity to add Google Maps to any Android project.
- Google Cloud Message: send push notifications to any Android device.
- AdMob: monetize any Android app.
You can find more information about these APIs on the Google Developers site.
Now learn how to integrate JSON with iOS
Discover some REST alternatives for real-time applications
How Microsoft plans to win over Android developers
Dig Deeper on API design and management
Related Q&A from Matthew David
Apple now supports two developmental languages. This means integrating JSON with iOS isn't as difficult as it might seem. Expert Matthew David ... Continue Reading
Here are several options for incorporating mobile apps as part of a legacy system modernization effort. Approaches include vendor apps and writing ... Continue Reading