Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/14.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在android中从返回类型void doInBackground获取数据以执行JSON解析_Android_Json_Facebook - Fatal编程技术网

如何在android中从返回类型void doInBackground获取数据以执行JSON解析

如何在android中从返回类型void doInBackground获取数据以执行JSON解析,android,json,facebook,Android,Json,Facebook,//大家好,我的问题是我的doinbackground是一个void类型,所以我想从它获取数据到postexecute,有人能给我一些建议如何将数据从doinbackground传输到postexecute吗 @Override protected Void doInBackground(Session... params) { Request r = new Request(params[0], "me/home");

//大家好,我的问题是我的doinbackground是一个void类型,所以我想从它获取数据到postexecute,有人能给我一些建议如何将数据从doinbackground传输到postexecute吗

        @Override
        protected Void doInBackground(Session... params) {


            Request r =  new Request(params[0], "me/home");

            Response res = Request.executeAndWait(r);
            try {
            GraphObject go = res.getGraphObject();


        JSONObject json = go.getInnerJSONObject();
        JSONArray jArray;

            jArray = json.getJSONArray("data");

        for (int i = 0; i < jArray.length(); i++) {
            JSONObject currObj = jArray.getJSONObject(i);
             userId = currObj.getString("id");
            if (currObj.has("message")) {
                userMessage = currObj.getString("message");
            }
            else if(currObj.has("story")){
                userMessage = currObj.getString("story");
            } else{
                userMessage = "no message/story set";
            }
            JSONObject fromObj = currObj
                    .getJSONObject("from");
            String from = fromObj.getString("name");

            HashMap<String, String>newslist = new HashMap<String, String>();
            newslist.put(id, userId);
            newslist.put(message, userMessage);
            newslist.put(name, name);

            list.add(newslist);


            }
        } catch (JSONException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }



            //Log.i("result", go.toString()); //HERE
            return null;
        }
一旦doInBackground()任务完成,将自动调用onPostExecute()任务。doInBackGround()方法将返回在doInBackGround()中完成的后台进程的结果

在代码中,可以更改doInBackGround()末尾的返回部分

然后,您可以访问onPostExecute()任务中的结果,参数如下

protected void onPostExecute(String result){ //Can use any data types
        super.onPostExecute(result);    
catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }



        //Log.i("result", go.toString()); //HERE
        return result;    
protected void onPostExecute(String result){ //Can use any data types
        super.onPostExecute(result);