forked from ringcentral/pubnub-jtools
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPubnubUtil.java
More file actions
50 lines (47 loc) · 1.1 KB
/
Copy pathPubnubUtil.java
File metadata and controls
50 lines (47 loc) · 1.1 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
package com.pubnub.api;
import com.codename1.io.Util;
import org.json.*;
/**
* PubnubUtil class provides utility methods like urlEncode etc
* @author Pubnub
*
*/
public class PubnubUtil extends PubnubUtilCore {
/**
* Returns encoded String
*
* @param sUrl
* , input string
* @return , encoded string
*/
public static String urlEncode(String sUrl) {
return Util.encodeUrl(sUrl);
}
/**
* Convert input String to JSONObject, JSONArray, or String
*
* @param str
* JSON data in string format
*
* @return JSONArray or JSONObject or String
*/
static Object stringToJSON(String str) {
try {
return new JSONArray(str);
} catch (JSONException e) {
}
try {
return new JSONObject(str);
} catch (JSONException ex) {
}
try {
return Integer.parseInt(str);
} catch (Exception ex) {
}
try {
return Double.parseDouble(str);
} catch (Exception ex) {
}
return str;
}
}