本文整理汇总了Java中com.android.volley.toolbox.JsonRequest类的典型用法代码示例。如果您正苦于以下问题:Java JsonRequest类的具体用法?Java JsonRequest怎么用?Java JsonRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
JsonRequest类属于com.android.volley.toolbox包,在下文中一共展示了JsonRequest类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendDateToSite
import com.android.volley.toolbox.JsonRequest; //导入依赖的package包/类
private void sendDateToSite(String httpurl, JSONObject jsonObject, final OnResponListener respon) {
JsonRequest<JSONObject> jsonRequest = new JsonObjectRequest(Method.POST, httpurl, jsonObject,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.i("onSite", "response -> " + response.toString());
respon.OnRespon(0, response.optString("id"));
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
respon.OnRespon(1, error.toString());
error.printStackTrace();
Log.i("onSite", "sendDateToSite请求失败" + error.toString());
}
}) {
@Override
public Map<String, String> getHeaders() {
return getHeaderWithToken();
}
};
mRequestQueue.add(jsonRequest);
}
示例2: createParamRequest
import com.android.volley.toolbox.JsonRequest; //导入依赖的package包/类
public JsonRequest<JSONObject> createParamRequest(final int method, final String url,
final Map<String, String> params,
final Response.Listener<JSONObject> onResponse,
final Response.ErrorListener onError) {
String queryString = UrlQueryString.buildQueryString(params);
String fullUrl = baseUrl + url + (queryString.length() > 0 ? "?" + queryString : "");
JsonObjectRequest request = new JsonObjectRequest(method, fullUrl, onResponse, onError) {
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
return headers;
}
@Override
public Map<String, String> getParams() {
Log.v("getParams", params.toString());
return params;
}
};
request.setShouldCache(false);
return request;
}
示例3: getMessages
import com.android.volley.toolbox.JsonRequest; //导入依赖的package包/类
public JsonRequest<JSONObject> getMessages() {
HashMap<String, String> params = new HashMap<String, String>();
JsonRequest<JSONObject> request = createParamRequest(Request.Method.GET, "/api/database/messages", params, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject jsonObject) {
Log.v("RestClient", jsonObject.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
Log.e("RestClient", volleyError.getMessage());
}
});
queue.add(request);
return request;
}
示例4: initData
import com.android.volley.toolbox.JsonRequest; //导入依赖的package包/类
private void initData() {
long id = PreferenceManager.getDefaultSharedPreferences(UploadService.this).getLong(LoginActivity.PRE_CURRENT_USER_ID, 0);
String club_id = String.valueOf(id);
String url = Constants.KTHOST + "users/get_role?user_id=" +
club_id + "&authenticity_token=" + MD5.getToken(Constants.KTHOST + "users/get_role");
JsonRequest jsonRequest = new JsonObjectRequest(url,
null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject jsonObject) {
Token token = new Gson().fromJson(jsonObject.toString(), new TypeToken<Token>() {
}.getType());
access_token = token.youku_token;
Log.d("access_token", access_token);
doUp(list.get(current));
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
}
}) {
@Override
public Map<String, String> getHeaders() {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Accept", "application/json");
headers.put("Content-Type", "application/json; charset=UTF-8");
return headers;
}
};
VolleyUtil.getInstance(getApplicationContext()).addRequest(jsonRequest);
}
示例5: test1
import com.android.volley.toolbox.JsonRequest; //导入依赖的package包/类
private void test1() {
Log.d("soulnq", "请求网络");
String url = Constants.KTHOST+"shool_user_tests/get_football_skills";
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("authenticity_token", "f3cc6394ca4696dab16061800aacd2d8");
Log.d("soulnq", jsonObject.toString());
} catch (JSONException e) {
e.printStackTrace();
}
JsonRequest<JSONObject> request = new JsonObjectRequest(com.android.volley.Request.Method.GET,
url, jsonObject, new com.android.volley.Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
ffff userMsg = new Gson().fromJson(response.toString(),new TypeToken<ffff>(){}.getType());
if (userMsg != null) {
Toast.makeText(ClubDataActivity3.this, "成功", Toast.LENGTH_LONG).show();
Toast.makeText(ClubDataActivity3.this, "数据:" + userMsg.toString(), Toast.LENGTH_LONG).show();
} else {
Toast.makeText(ClubDataActivity3.this, "失败", Toast.LENGTH_LONG).show();
}
}
}, new com.android.volley.Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
Toast.makeText(ClubDataActivity3.this, "失败", Toast.LENGTH_LONG).show();
}
})
{
@Override
public Map<String, String> getHeaders() {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Accept", "application/json");
headers.put("Content-Type", "application/json; charset=UTF-8");
return headers;
}
};
VolleyUtil.getInstance(getApplicationContext()).addRequest(request);
}
示例6: onStart
import com.android.volley.toolbox.JsonRequest; //导入依赖的package包/类
@Override
protected void onStart() {//从服务器获取数据
super.onStart();
long uer_id = PreferenceManager.getDefaultSharedPreferences(this).getLong(LoginActivity.PRE_CURRENT_USER_ID,0);
String id = String.valueOf(uer_id);
String url = Constants.KTHOST+"games/new?user_id=" + id +
"&authenticity_token="+MD5.getToken(Constants.KTHOST+"games/new");
JsonRequest<JSONObject> jsonRequest = new JsonObjectRequest(
url,
null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject jsonObject) {
LogUtils.e(jsonObject.toString());
gsonAnalysis(jsonObject.toString());
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
Log.d("volleyError=====",volleyError.toString());
}
}){
@Override
public Map<String, String> getHeaders() {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Accept", "application/json");
headers.put("Content-Type", "application/json; charset=UTF-8");
return headers;
}
};
VolleyUtil.getInstance(this).addRequest(jsonRequest);
}
示例7: addRequest
import com.android.volley.toolbox.JsonRequest; //导入依赖的package包/类
private void addRequest(String url) {
JsonRequest jsonRequest = new JsonObjectRequest(Request.Method.GET, url, null, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
JSONObject location = response.getJSONArray("results").getJSONObject(0).getJSONObject("geometry").getJSONObject("location");
double latitude = location.getDouble("lat");
double longitude = location.getDouble("lng");
LatLng latLng = new LatLng(latitude, longitude);
goToLocation(latLng);
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
});
requestQueue.add(jsonRequest);
}
示例8: login
import com.android.volley.toolbox.JsonRequest; //导入依赖的package包/类
public JsonRequest<JSONObject> login(String username, String password,
Response.Listener<JSONObject> onResponse,
Response.ErrorListener onError) {
JSONObject params = new JSONObject();
try {
params.put("username", username);
params.put("password", password);
} catch (Exception e) {
e.printStackTrace();
}
JsonRequest<JSONObject> request = createJsonRequest(Request.Method.POST, "/login", params, onResponse, onError);
queue.add(request);
return request;
}
示例9: callDeviceAction
import com.android.volley.toolbox.JsonRequest; //导入依赖的package包/类
public JsonRequest<JSONObject> callDeviceAction(Device device, String actionName, Map<String, String> params,
Response.Listener<JSONObject> onResponse,
Response.ErrorListener onError) {
JsonRequest<JSONObject> request = createParamRequest(
Request.Method.GET,
"/api/device/" + device.getId() + "/" + actionName,
params,
onResponse,
onError
);
queue.add(request);
return request;
}
示例10: addRequest
import com.android.volley.toolbox.JsonRequest; //导入依赖的package包/类
public void addRequest(JsonRequest<?> newRequest) {
if (newRequest == null)
return;
newRequest.setTag(TAG);
mRequestQueue.add(newRequest);
return;
}
示例11: updateToNewLocation
import com.android.volley.toolbox.JsonRequest; //导入依赖的package包/类
private void updateToNewLocation(Location location) {
if (location != null){
latitude = location.getLatitude();
longitude = location.getLongitude();
}
//搜索当前城市
String uri = "http://restapi.amap.com/v3/geocode/regeo?key="
+ KEY + "&location=" + longitude + "," + latitude +
"&poitype=&radius=&extensions=base&batch=false&roadlevel=";
JsonRequest<JSONObject> jsonRequest = new JsonObjectRequest(
Request.Method.GET,
uri,
null,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject jsonObject) {
try {
JSONObject jsonObject1 = new JSONObject(jsonObject.toString());
JSONObject jsonObject2 = jsonObject1.getJSONObject("regeocode");
JSONObject jsonObject3 = jsonObject2.getJSONObject("addressComponent");
address = jsonObject3.getString("province");
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError volleyError) {
Log.d("------volleyError",volleyError.toString());
}
}
){
@Override
public Map<String, String> getHeaders() {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Accept", "application/json");
headers.put("Content-Type", "application/json; charset=UTF-8");
return headers;
}
};
VolleyUtil.getInstance(this).addRequest(jsonRequest);
}
示例12: login
import com.android.volley.toolbox.JsonRequest; //导入依赖的package包/类
public void login(){
String url = Constants.KTHOST+"users/login";
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("account", user);
jsonObject.put("password", password);
jsonObject.put("authenticity_token", MD5.getToken(url));
} catch (JSONException e) {
e.printStackTrace();
}
JsonRequest<JSONObject> jsonRequest = new JsonObjectRequest(Request.Method.POST,url, jsonObject,
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
closeLoadingDialog();
LogUtils.e(response.toString());
//关闭动画
//解析从服务器上接收到的json数据
UserMsg userMsg = new Gson().fromJson(response.toString(),new TypeToken<UserMsg>(){}.getType());
KTApplication.setLocalUserInfo(response.toString());
//返回的是错误
if (userMsg.response.equals("error")){
showDialogToast("用户名密码错误");
} else if (userMsg.is_school_manager == 0){
showDialogToast("您不是校园俱乐部管理");
} else if (userMsg.is_judge == 0){//如果不是裁判
showDialogToast("没有裁判权限");
} else {
PreferenceManager.getDefaultSharedPreferences(LoginActivity.this)
.edit()
.putLong(PRE_CURRENT_USER_ID,userMsg.user_id)
.putLong(PRE_CURRENT_CLUB_ID,userMsg.club_id)
.putString(PRE_CURRENT_CLUB_NAME,userMsg.club_name)
.putInt(PRE_CURRENT_TAYPE,userMsg.school_role.role_type)
.commit();
//把俱乐部的id用意图传递过去
Intent intent = new Intent(LoginActivity.this,ClubDataActivity3.class);
startActivity(intent);
finish();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
closeLoadingDialog();
//关闭动画
showDialogToast("网络错误");
}
})
{
@Override
public Map<String, String> getHeaders() {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Accept", "application/json");
headers.put("Content-Type", "application/json; charset=UTF-8");
return headers;
}
};
VolleyUtil.getInstance(getApplicationContext()).addRequest(jsonRequest);
}
示例13: onErrorResponse
import com.android.volley.toolbox.JsonRequest; //导入依赖的package包/类
@Override
public void onErrorResponse(VolleyError error) {
final CoverListener listenerReference = this;
new AsyncTask<Void,Void,Void>(){
@Override
protected Void doInBackground(Void... voids) {
if(mManga != null) {
if (mUrlError == null) {
mUrlError = new HashSet<String>(3);
}
mUrlError.add(mManga.cover);
if (mRetries > 0) {
Log.d(TAG, "Cover: " + mManga.cover + "\nAsk to: " + Internet.HOST + "manga/" + mManga._id + "/cover?" + Internet.arrayParams(mUrlError, "e"));
App.getInstance().addToRequestQueue(
new MangaRequest(
JsonRequest.Method.GET,
Internet.HOST + "manga/" + mManga._id + "/cover?" + Internet.arrayParams(mUrlError, "e"),
new Response.Listener<Manga>() {
@Override
public void onResponse(Manga response) {
Log.d(TAG, response.toString());
if (response.cover != null) {
Log.d(TAG, "New cover received: " + response.title + " " + response.cover);
mManga.cover = response.cover;
// Reload image
ImageCacheManager.getInstance().getImage(mManga.cover, mImageView, listenerReference);
// Update database
DatabaseHelper dbs = OpenHelperManager.getHelper(
App.getInstance().getApplicationContext(),
DatabaseHelper.class);
dbs.getMangaRunDao().update(mManga);
OpenHelperManager.releaseHelper();
} else {
Log.d(TAG, "There aren't new covers for: " + mManga.title);
}
}
},
null
),
"New Cover"
);
mRetries--;
} else {
Log.d(TAG, "Reached maximum intents number for ask a new cover with: " + mManga.cover);
}
}
return null;
}
}.execute();
}
示例14: getRequestResponseText
import com.android.volley.toolbox.JsonRequest; //导入依赖的package包/类
/**
* Gets Request response information.
*
* @param request
* Request instance to retrieve information for logging
*
* @param response
* Response instance to retrieve information for logging
*
* @return Message describing response, including Method type, URL and JSON response
* */
static String getRequestResponseText(JsonRequest<?> request, JSONObject response)
{
StringBuilder msg = new StringBuilder();
msg.append( methodToString( request.getMethod() ) ).append(" request successful ").append("\n");
msg.append("URL: ").append(request.getUrl()).append("\n");
msg.append("Response: ").append(response.toString()).append("\n");
return msg.toString();
}