how to get data from Json object?

后端 未结 3 1599
花落未央
花落未央 2021-01-12 18:46

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 run         


        
相关标签:
3条回答
  • 2021-01-12 19:13
    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/

    0 讨论(0)
  • 2021-01-12 19:19

    Edit your code like this ...this may help you..

    JSONObject resultObject = new JSONObject(response);
    
    JSONArray JArray = resultObject.getJSONArray("data");
    
                    for (int t=0; t<JArray.length(); t++) {
    
                        JSONObject JObject = JtArray.getJSONObject(t);
    
    
    
    builder.append(JObject.getString("uid")+": ");
    
    0 讨论(0)
  • 2021-01-12 19:22

    In java, It's solved as

    String jsonString = yourstring;
    JSONObject data = JSON.parse(jsonString);
    
    //reading data using index
    long firstData_uid = data["data"][0]["uid"];
    String firstData_birthday = data["data"][0]["birthday"];
    String firstData_name = data["data"][0]["name"];
    

    In javascript, It's solved as

    var jsonString = yourstring;
    var data = JSON.parse(jsonString);
    
    //reading data using index
    var firstData_uid = data["data"][0]["uid"];
    var firstData_birthday = data["data"][0]["birthday"];
    var firstData_name = data["data"][0]["name"];
    
    0 讨论(0)
提交回复
热议问题