您的位置:首页 > Web前端 > JavaScript

解析服务器返回的Json 数据的工具类

2017-01-11 17:37 429 查看
/**
* 解析服务器返回的Json 数据的工具类
*  Created by leven on 2016/10/26.
*/
public class JsonParseUtils {

/**
* @param response 服务器返回的 json 字符串
* @return 请求的状态码
*/
public static String getErrorCode(String response) {
JSONObject jsonObject = null;
try {
jsonObject = new JSONObject(response);
String errorCode = jsonObject.getString("errorCode");
return errorCode;
} catch (JSONException e) {
e.printStackTrace();
return "-1";
}
}

/**
* 判断网络请求数据是否成功
* @param response 返回的json数据
* @return
*/
public static boolean isSuccess(String response) {
JSONObject jsonObject = null;
try {
jsonObject = new JSONObject(response);
boolean isSuccess = jsonObject.getBoolean("isSuccess");
return isSuccess;
} catch (JSONException e) {
e.printStackTrace();
return false;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Json工具类 Android