当前位置: 首页>>代码示例>>Java>>正文


Java JsonObjectRequest类代码示例

本文整理汇总了Java中com.android.volley.toolbox.JsonObjectRequest的典型用法代码示例。如果您正苦于以下问题:Java JsonObjectRequest类的具体用法?Java JsonObjectRequest怎么用?Java JsonObjectRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


JsonObjectRequest类属于com.android.volley.toolbox包,在下文中一共展示了JsonObjectRequest类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: volleySyncRequest

import com.android.volley.toolbox.JsonObjectRequest; //导入依赖的package包/类
/**
 * Effettua una web request sincrona tramite Volley API, restituendo in risposta
 * l'oggetto JSON scaricato.
 */
public static JSONObject volleySyncRequest(Context c, String url) {

    // configurazione della webRequest
    RequestFuture<JSONObject> future = RequestFuture.newFuture();
    JsonObjectRequest request = new JsonObjectRequest(url, null, future, future);
    RequestQueue requestQueue = Volley.newRequestQueue(c);
    requestQueue.add(request);

    // esecuzione sincrona della webRequest
    try {
        // limita la richiesta bloccante a un massimo di 10 secondi, quindi restituisci
        // la risposta.
        return future.get(10, TimeUnit.SECONDS);

    } catch (InterruptedException | TimeoutException | ExecutionException e) {
        e.printStackTrace();
    }

    return null;
}
 
开发者ID:IelloDevTeam,项目名称:IelloAndroidApp,代码行数:25,代码来源:HelperRete.java

示例2: requestPersonCredits

import com.android.volley.toolbox.JsonObjectRequest; //导入依赖的package包/类
private static void requestPersonCredits(String url, final GetMoviesCallback callback,
                                     Activity activity) {
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    callback.successGetMovies(MoviesMapping.getMoviesFromCredits(response));
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    error.printStackTrace();
                    callback.errorGetMovies();
                }
            });
    VolleyHelper.getInstance(activity).addToRequestQueue(request, activity);
}
 
开发者ID:JonathandelaSen,项目名称:TheMovies,代码行数:19,代码来源:PeopleTask.java

示例3: get

import com.android.volley.toolbox.JsonObjectRequest; //导入依赖的package包/类
/**
 * 请求返回JSONObject对象 Get请求 无参数,或者get请求的参数直接拼接在URL上面
 * @param url   请求地址
 * @param listener  数据回调接口
 */
public void get(String url, final Fdv_CallBackListener<JSONObject> listener){
    JsonObjectRequest jsonObjectRequest=new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
                if(listener!=null){
                    listener.onSuccessResponse(response);
                }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if(listener!=null){
                listener.onErrorResponse(error);
            }
        }
    });
    addRequest(jsonObjectRequest);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:Fdv_JsonObjectRequest.java

示例4: post

import com.android.volley.toolbox.JsonObjectRequest; //导入依赖的package包/类
/**
 * 发送POST请求, 返回JSONObject对象数据
 * @param url    请求地址
 * @param listener  数据返回回调接口
 * @param params   POST请求参数
 */
public void post(String url, final Fdv_CallBackListener<JSONObject> listener,Map<String,String> params){
    JsonObjectRequest jsonObjectRequest=new JsonObjectRequest(Request.Method.POST, url, null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            if(listener!=null){
                listener.onSuccessResponse(response);
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            if(listener!=null){
                listener.onErrorResponse(error);
            }
        }
    });
    addRequest(jsonObjectRequest,params);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:25,代码来源:Fdv_JsonObjectRequest.java

示例5: fetchLatestVersion

import com.android.volley.toolbox.JsonObjectRequest; //导入依赖的package包/类
public static void fetchLatestVersion(final ModelListener<String> listener) {
    JsonObjectRequest r = new JsonObjectRequest(Request.Method.GET, baseURL + "/latest", null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    try {
                        JSONObject result = response.getJSONObject("result");
                        String version = result.getString("android");
                        listener.onData(version, "ok");
                    } catch (Exception e) {
                        e.printStackTrace();
                        listener.onData(null, "服务器通信失败 (1)");
                    }
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            error.printStackTrace();
            listener.onData(null, "服务器通信失败 (1)");
        }
    });
    SAGlobal.sharedRequestQueue.add(r);
}
 
开发者ID:njitdev,项目名称:sa-android,代码行数:24,代码来源:VersionModels.java

示例6: authInit

import com.android.volley.toolbox.JsonObjectRequest; //导入依赖的package包/类
public static void authInit(final ModelListener<AuthInitInfo> listener) {
    JsonObjectRequest req = new JsonObjectRequest(Request.Method.GET, baseURL + "/auth/init", null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            try {
                JSONObject result = response.getJSONObject("result");

                AuthInitInfo authInitInfo = new AuthInitInfo();
                authInitInfo.session_id = result.getString("session_id");
                authInitInfo.captcha_enabled = result.getBoolean("captcha_enabled");

                listener.onData(authInitInfo, "ok");
            } catch (JSONException e) {
                listener.onData(null, "教务系统返回非法数据");
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            listener.onData(null, "教务系统太烂无法通信,请稍后再试");
        }
    });
    SAGlobal.sharedRequestQueue.add(req);
}
 
开发者ID:njitdev,项目名称:sa-android,代码行数:25,代码来源:SchoolSystemModels.java

示例7: sendStartEvent

import com.android.volley.toolbox.JsonObjectRequest; //导入依赖的package包/类
public static void sendStartEvent(String installationID) {
    // Prepare parameters
    Map<String, String> map = new HashMap<>();
    map.put("installation_id", installationID);
    map.put("school", SAConfig.schoolIdentifier);
    map.put("client_version", BuildConfig.VERSION_NAME);
    map.put("device_info", SAUtils.getDeviceModel());
    JSONObject params = new JSONObject(map);

    // Make request
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, baseURL + "/start", params, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {}
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {}
    });
    SAGlobal.sharedRequestQueue.add(jsonObjectRequest);
}
 
开发者ID:njitdev,项目名称:sa-android,代码行数:20,代码来源:AnalyticsModels.java

示例8: fetchArticleBody

import com.android.volley.toolbox.JsonObjectRequest; //导入依赖的package包/类
public static void fetchArticleBody(String articleID, final ModelListener<String> listener) {
    JsonObjectRequest r = new JsonObjectRequest(Request.Method.GET, articleURL + "?article_id=" + articleID, null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    try {
                        JSONObject article = response.getJSONObject("result");
                        String article_body = article.getString("article_body");
                        listener.onData(article_body, "ok");
                    } catch (JSONException e) {
                        e.printStackTrace();
                        listener.onData(null, "获取通知信息失败");
                    }
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            error.printStackTrace();
            listener.onData(null, "获取通知信息失败");
        }
    });
    SAGlobal.sharedRequestQueue.add(r);
}
 
开发者ID:njitdev,项目名称:sa-android,代码行数:24,代码来源:AnnouncementModels.java

示例9: submitPost

import com.android.volley.toolbox.JsonObjectRequest; //导入依赖的package包/类
public static void submitPost(Post post, final ModelListener<Boolean> listener) {
    // Prepare parameters
    Map<String, String> map = new HashMap<>();
    map.put("installation_id", post.installation_id);
    map.put("text", post.text);
    map.put("user_name", post.user_name);
    map.put("user_contact", post.user_contact);
    JSONObject params = new JSONObject(map);

    // Make request
    JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, baseURL + "/posts", params, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            listener.onData(true, "发送留言成功");
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            listener.onData(false, "发送留言失败");
        }
    });
    SAGlobal.sharedRequestQueue.add(jsonObjectRequest);
}
 
开发者ID:njitdev,项目名称:sa-android,代码行数:24,代码来源:MessageBoardModels.java

示例10: volleyPostJsonObjectRequest

import com.android.volley.toolbox.JsonObjectRequest; //导入依赖的package包/类
private String volleyPostJsonObjectRequest() {
    HashMap<String, String> hashMap = new HashMap<>();
    hashMap.put("phone", "13429667914");
    hashMap.put("key", Constant.JUHE_API_KEY);
    JSONObject object = new JSONObject(hashMap);
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.POST, Constant.JUHE_URL_POST, object,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Toast.makeText(MainActivity.this, response.toString(), Toast.LENGTH_SHORT).show();

                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(MainActivity.this, error.toString(), Toast.LENGTH_SHORT).show();
                }
            });
    request.setTag(JSON_OBJECT_POST_TAG);
    MyApplication.getHttpQueues().add(request);
    return request.getTag().toString();
}
 
开发者ID:InnoFang,项目名称:Android-Code-Demos,代码行数:24,代码来源:MainActivity.java

示例11: volleyGetJsonObjectRequest

import com.android.volley.toolbox.JsonObjectRequest; //导入依赖的package包/类
private String volleyGetJsonObjectRequest() {
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, Constant.JUHE_URL_GET, null, // 用post方式时,需更改为带请求参数的Object
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    Toast.makeText(MainActivity.this, response.toString(), Toast.LENGTH_SHORT).show();
                }
    },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    Toast.makeText(MainActivity.this, error.toString(), Toast.LENGTH_SHORT).show();
                }
        });
    request.setTag(JSON_OBJECT_GET_TAG);
    MyApplication.getHttpQueues().add(request);
    return request.getTag().toString();
}
 
开发者ID:InnoFang,项目名称:Android-Code-Demos,代码行数:19,代码来源:MainActivity.java

示例12: UseJsonRequest

import com.android.volley.toolbox.JsonObjectRequest; //导入依赖的package包/类
private void UseJsonRequest() {
    String requestBody = "ip=59.108.54.37";
    JsonObjectRequest mJsonObjectRequest = new JsonObjectRequest(Request.Method.POST, "http://ip.taobao.com/service/getIpInfo.php?ip=59.108.54.37",
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    IpModel ipModel = new Gson().fromJson(response.toString(), IpModel.class);
                    if (null != ipModel && null != ipModel.getData()) {
                        String city = ipModel.getData().getCity();
                        Log.d(TAG, city);
                    }
                }
            }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e(TAG, error.getMessage(), error);
        }
    }
    );
    mQueue.add(mJsonObjectRequest);
}
 
开发者ID:henrymorgen,项目名称:android-advanced-light,代码行数:22,代码来源:MainActivity.java

示例13: getPosts

import com.android.volley.toolbox.JsonObjectRequest; //导入依赖的package包/类
void getPosts() {
    String url = getArguments().getString(ARG_SECTION_URL);
    url = getString(R.string.tumblr_api_url, url);
    JsonObjectRequest request = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
        @Override
        public void onResponse(JSONObject response) {
            try {
                JSONObject meta = response.getJSONObject("meta");
                if (meta.getInt("status") == 200) {
                    JSONArray posts = response.getJSONObject("response").getJSONArray("posts");
                    adapter.setPosts(posts);
                }
            } catch (JSONException e) {
                e.printStackTrace();
            }
        }
    }, new Response.ErrorListener() {
        @Override
        public void onErrorResponse(VolleyError error) {
            Log.e("Activities", error.toString());
        }
    });

    VolleySingleton.getInstance(getContext()).addToRequestQueue(request);
}
 
开发者ID:ypicoleal,项目名称:FancyTab,代码行数:26,代码来源:MainActivity.java

示例14: voiceRequest

import com.android.volley.toolbox.JsonObjectRequest; //导入依赖的package包/类
/**
 * Volley call for the JSON containing the voices list
 * Create the request and add it to the requestqueue, then return the result or null if there was an error
 * @param request String containing the path to the voices on the server
 */
private void voiceRequest(String request) {
    JsonObjectRequest jsonRequest = new JsonObjectRequest(this.getUrl() + request,null,
            new Response.Listener<JSONObject>() {
                @Override
                public void onResponse(JSONObject response) {
                    options.returnTTSOption(response);
                }
            },
            new Response.ErrorListener() {
                @Override
                public void onErrorResponse(VolleyError error) {
                    options.returnTTSOption(null);
                }
            });
    requestQueue.addToRequestQueue(jsonRequest);


}
 
开发者ID:Visions-Team,项目名称:eBread,代码行数:24,代码来源:InterfaceFATTS.java

示例15: tokensRequest

import com.android.volley.toolbox.JsonObjectRequest; //导入依赖的package包/类
/**
 * Volley call for the JSON containing the tokens, async method
 * Create the request and add it to the requestqueue, then return the result or null if there was an error
 * @param FATTScall HashMap containing all the data to make the HTTP request
 */
private void tokensRequest(HashMap<String, String> FATTScall) {
JsonObjectRequest jsonRequest = new JsonObjectRequest(this.getUrl()  + "/say" + "?" + InterfaceFATTS.mapToGETQuery(FATTScall),null,
    new Response.Listener<JSONObject>() {
            @Override
            public void onResponse(JSONObject response) {
                prepareSyncData(response);
            }
        },
        new Response.ErrorListener() {
            @Override
            public void onErrorResponse(VolleyError error) {
                syncArray = (null);
                respondToActivity();
            }
        });
    requestQueue.addToRequestQueue(jsonRequest);


}
 
开发者ID:Visions-Team,项目名称:eBread,代码行数:25,代码来源:InterfaceFATTS.java


注:本文中的com.android.volley.toolbox.JsonObjectRequest类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。