如何从JSON对象的数据? [英] how to get data from Json object?

查看:100
本文介绍了如何从JSON对象的数据?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我工作的一个Android应用程序是与Facebook集成。我使用FQL查询获取来自Facebook的信息。我FQL方法

 无效runfql(){
                字符串fqlQuery =SELECT UID,名称,pic_small,生日从用户其中UID IN+
                  (SELECT UID2从朋友哪里UID1 =我());
                捆绑PARAMS =新包();
                params.putString(Q,fqlQuery);
                会话会话= Session.getActiveSession();
                请求请求=新的请求(会话,
                / FQL
                参数,可以
                HttpMethod.GET,
                新Request.Callback(){
                        公共无效onCompleted(响应响应){

                        JSONObject的myjson = response.getGraphObject()getInnerJSONObject()。
                        Log.d(ResultResultResult:,+ myjson);
                        }
                    });
                    Request.executeBatchAsync(要求);

                }
 

myjson对象的所有信息我想要的。像这样

  {数据:[{UID:536089174,生日:7月22日,名:奥斯曼阿斯拉姆谢赫},{UID: 581379174,生日:7月26日,名:阿马尔·哈立德}
 

问题是如何把信息存储到不同的阵列?

请正确一些code用于这一目的。

解决方案

 字符串jsonString = yourstring;
JSONObject的jsonResult =新的JSONObject(jsonString);
JSONArray数据= jsonResult.getJSONArray(数据);
如果(数据!= NULL){
    的String []的名称=新的String [data.length()];
    的String []生日=新的String [data.length()];
    的for(int i = 0; I< data.length();我++){
        生日[I] = data.getString(生日);
        名称[I] = data.getString(姓名);
    }
}
 

检查<一href="http://www.androidhive.info/2012/01/android-json-parsing-tutorial/">http://www.androidhive.info/2012/01/android-json-parsing-tutorial/

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.?

解决方案

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/

这篇关于如何从JSON对象的数据?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆