Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get data from Json object?

i am working on a android app which is integrated with facebook . i am using fql query to fetch info from facebook. my fql method is

                void runfql(){
                String fqlQuery = "SELECT uid, name, pic_small,birthday FROM user WHERE uid IN " +
                  "(SELECT uid2 FROM friend WHERE uid1 = me() )";
                Bundle params = new Bundle();
                params.putString("q", fqlQuery);
                Session session = Session.getActiveSession();
                Request request = new Request(session,
                "/fql",                         
                params,                         
                HttpMethod.GET,                 
                new Request.Callback(){         
                        public void onCompleted(Response response) {

                        JSONObject myjson=response.getGraphObject().getInnerJSONObject();
                        Log.d("ResultResultResult: " ,""+myjson);                           
                        }                  
                    }); 
                    Request.executeBatchAsync(request);  

                } 

myjson object has all info i want. like this

 {"data":[{"uid":536089174,"birthday":"July 22","name":"Usman Aslam Sheikh"},{"uid":581379174,"birthday":"July 26","name":"Ammar Khalid"}

question is how to store that information into different arrays??

please right some code for this purpose.?

like image 761
user2132063 Avatar asked Apr 10 '13 06:04

user2132063


People also ask

How can I get data from JSON?

Any JSON data can be consumed from different sources like a local JSON file by fetching the data using an API call. After getting a response from the server, you need to render its value. You can use local JSON files to do an app config, such as API URL management based on a server environment like dev, QA, or prod.

How get data from JSON to HTML?

The jQuery code uses getJSON() method to fetch the data from the file's location using an AJAX HTTP GET request. It takes two arguments. One is the location of the JSON file and the other is the function containing the JSON data. The each() function is used to iterate through all the objects in the array.

Can you fetch a JSON file?

One standard method we can use to read a JSON file (either a local file or one uploaded to a server) is with the Fetch API. It uses the same syntax for both. The only difference would be the URL. To fix this, we will make sure our JSON file is on a local or remote server.


1 Answers

String jsonString = yourstring;
JSONObject jsonResult = new JSONObject(jsonString);
JSONArray data = jsonResult.getJSONArray("data");
if(data != null) {
    String[] names = new String[data.length()];
    String[] birthdays = new String[data.length()];
    for(int i = 0 ; i < data.length() ; i++) {
        birthdays[i] = data.getString("birthday");
        names[i] = data.getString("name");
    }
}

check http://www.androidhive.info/2012/01/android-json-parsing-tutorial/

like image 192
Nermeen Avatar answered Sep 28 '22 19:09

Nermeen