Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
262 views
in Technique[技术] by (71.8m points)

android - Using a custom API

I just started using the website http://www.kimonolabs.com and created an API as I need to retrieve data from my school website to put into the school app I am creating. Unfortunately, I do not really plan ahead, and this leads me to my 2 questions:

1) How do I include this API in my school Android App?

2) How do I parse the JSON in this API? (Or just linking me to another page on this would be equally as greatly appreciated :) )

Thanks very much for any help you can give! Sorry for my language, I am 14 :P

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

First things first. Take a look at AsyncTask in Android. AsyncTask is used to perform operations asynchronously. Take a look at this answer explaining how parameters are passed to AsyncTask.

You can use libraries mentioned bellow to do same thing:

  1. Asynchronous Http Client
  2. Volley

Once you communicate with server and receive response, you have to parse JSON data.

The key you have to remember for this is

[] - square bracket represents JSON Array
{} - curly bracket represents JSON Object

Everything else will be combination of these.

This tutorial will help you regarding JSON parsing.

JSON object to Java object conversion

To convert json data to java object you can use:

  1. Jackson
  2. Gson

Follow this link or this link for nice GSON tutorial.

I personally used GSON, and it is best library for json to java object conversion.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...