Skip to content

Commit

Permalink
ParseUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
yechaoa committed Sep 12, 2017
1 parent e92df23 commit 4b2c481
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions app/src/main/java/com/yechaoa/yutils/ParseUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.yechaoa.yutils;

import org.json.JSONException;
import org.json.JSONObject;

/**
* Created by yechao on 2017/3/21.
* Describe : 直接解析Json
* <p>
* GitHub : https://github.com/yechaoa
* CSDN : http://blog.csdn.net/yechaoa
*/

public class ParseUtil {

/**
* {
* "code": "0",
* "data": "修改成功",
* "flag": true,
* "info": null,
* "infoValues": null
* }
*/

//解析Code
public static String parseCode(String response) {
String code = "";
try {
JSONObject json = new JSONObject(response);
code = json.getString("code");
} catch (JSONException e) {
e.printStackTrace();
}
return code;
}

//解析Flag
public static boolean parseFlag(String response) {
boolean flag = false;
try {
JSONObject json = new JSONObject(response);
flag = json.getBoolean("flag");
} catch (JSONException e) {
e.printStackTrace();
}
return flag;
}

//解析data
public static String parseData(String response, String key) {
String data = "";
try {
JSONObject json = new JSONObject(response);
data = json.getString(key);
} catch (JSONException e) {
e.printStackTrace();
}
return data;
}

}

0 comments on commit 4b2c481

Please sign in to comment.