Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
252 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...