Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
io.flutter.plugin.common.JSONUtil Class Reference

Static Public Member Functions

static Object unwrap (@Nullable Object o)
 
static Object wrap (@Nullable Object o)
 

Detailed Description

Definition at line 14 of file JSONUtil.java.

Member Function Documentation

◆ unwrap()

static Object io.flutter.plugin.common.JSONUtil.unwrap ( @Nullable Object  o)
inlinestatic

Convert the Json java representation to Java objects. Particularly used for converting JSONArray and JSONObject to Lists and Maps.

Definition at line 22 of file JSONUtil.java.

22 {
23 if (JSONObject.NULL.equals(o) || o == null) {
24 return null;
25 }
26 if (o instanceof Boolean
27 || o instanceof Byte
28 || o instanceof Character
29 || o instanceof Double
30 || o instanceof Float
31 || o instanceof Integer
32 || o instanceof Long
33 || o instanceof Short
34 || o instanceof String) {
35 return o;
36 }
37 try {
38 if (o instanceof JSONArray) {
39 List<Object> list = new ArrayList<>();
40 JSONArray array = (JSONArray) o;
41 for (int i = 0; i < array.length(); i++) {
42 list.add(unwrap(array.get(i)));
43 }
44 return list;
45 }
46 if (o instanceof JSONObject) {
47 Map<String, Object> map = new HashMap<>();
48 JSONObject jsonObject = (JSONObject) o;
49 Iterator<String> keyIterator = jsonObject.keys();
50 while (keyIterator.hasNext()) {
51 String key = keyIterator.next();
52 map.put(key, unwrap(jsonObject.get(key)));
53 }
54 return map;
55 }
56 } catch (Exception ignored) {
57 }
58 return null;
59 }
void add(sk_sp< SkIDChangeListener > listener) SK_EXCLUDES(fMutex)
static Object unwrap(@Nullable Object o)
Definition JSONUtil.java:22
SI auto map(std::index_sequence< I... >, Fn &&fn, const Args &... args) -> skvx::Vec< sizeof...(I), decltype(fn(args[0]...))>
Definition SkVx.h:680

◆ wrap()

static Object io.flutter.plugin.common.JSONUtil.wrap ( @Nullable Object  o)
inlinestatic

Backport of JSONObject#wrap(Object) for use on pre-KitKat systems.

Definition at line 63 of file JSONUtil.java.

63 {
64 if (o == null) {
65 return JSONObject.NULL;
66 }
67 if (o instanceof JSONArray || o instanceof JSONObject) {
68 return o;
69 }
70 if (o.equals(JSONObject.NULL)) {
71 return o;
72 }
73 try {
74 if (o instanceof Collection) {
75 JSONArray result = new JSONArray();
76 for (Object e : (Collection) o) result.put(wrap(e));
77 return result;
78 } else if (o.getClass().isArray()) {
79 JSONArray result = new JSONArray();
80 int length = Array.getLength(o);
81 for (int i = 0; i < length; i++) result.put(wrap(Array.get(o, i)));
82 return result;
83 }
84 if (o instanceof Map) {
85 JSONObject result = new JSONObject();
86 for (Map.Entry<?, ?> entry : ((Map<?, ?>) o).entrySet())
87 result.put((String) entry.getKey(), wrap(entry.getValue()));
88 return result;
89 }
90 if (o instanceof Boolean
91 || o instanceof Byte
92 || o instanceof Character
93 || o instanceof Double
94 || o instanceof Float
95 || o instanceof Integer
96 || o instanceof Long
97 || o instanceof Short
98 || o instanceof String) {
99 return o;
100 }
101 if (o.getClass().getPackage().getName().startsWith("java.")) {
102 return o.toString();
103 }
104 } catch (Exception ignored) {
105 }
106 return null;
107 }
static Object wrap(@Nullable Object o)
Definition JSONUtil.java:63
GAsyncResult * result
size_t length

The documentation for this class was generated from the following file: