-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJsonUtils.java
More file actions
53 lines (46 loc) · 1.28 KB
/
JsonUtils.java
File metadata and controls
53 lines (46 loc) · 1.28 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package common.android.fiot.androidcommon;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import org.json.JSONTokener;
/**
* Created by NT on 12/8/2015.
*/
public class JsonUtils {
/***
* convert string from server to jsonArray for parse
* @param data is String
* @return
*/
public static JSONArray getJsonArray(String data) {
JSONArray jsonArray = null;
try {
Object json = new JSONTokener(data).nextValue();
if (json instanceof JSONArray) {
jsonArray = (JSONArray) json;
return jsonArray;
}
} catch (JSONException e) {
e.printStackTrace();
}
return jsonArray;
}
/***
* convert string from server to json object for parse
* @param data is String
* @return
*/
public static JSONObject getJsonObject(String data) {
JSONObject jsonObject = null;
try {
Object json = new JSONTokener(data).nextValue();
if (json instanceof JSONObject) {
jsonObject = (JSONObject) json;
return jsonObject;
}
} catch (JSONException e) {
e.printStackTrace();
}
return jsonObject;
}
}