本文整理匯總了Java中org.json.JSONException類的典型用法代碼示例。如果您正苦於以下問題:Java JSONException類的具體用法?Java JSONException怎麽用?Java JSONException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
JSONException類屬於org.json包,在下文中一共展示了JSONException類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getArrayString
import org.json.JSONException; //導入依賴的package包/類
public static String[] getArrayString(JSONObject docObj, String name) {
String[] list = null;
if (docObj.has(name)) {
JSONArray json;
try {
json = docObj.getJSONArray(name);
int lenFeatures = json.length();
list = new String[lenFeatures];
for (int j = 0; j < lenFeatures; j++) {
String f = json.getString(j);
list[j] = f;
}
} catch (JSONException e) {
e.printStackTrace();
}
}
return list;
}
示例2: toJSON
import org.json.JSONException; //導入依賴的package包/類
public static JSONObject toJSON(View view) throws JSONException {
UiThreadUtil.assertOnUiThread();
JSONObject result = new JSONObject();
result.put("n", view.getClass().getName());
result.put("i", System.identityHashCode(view));
Object tag = view.getTag();
if (tag != null && tag instanceof String) {
result.put("t", tag);
}
if (view instanceof ViewGroup) {
ViewGroup viewGroup = (ViewGroup) view;
if (viewGroup.getChildCount() > 0) {
JSONArray children = new JSONArray();
for (int i = 0; i < viewGroup.getChildCount(); i++) {
children.put(i, toJSON(viewGroup.getChildAt(i)));
}
result.put("c", children);
}
}
return result;
}
示例3: parseJson
import org.json.JSONException; //導入依賴的package包/類
public ArrayList<ProblemData> parseJson() throws JSONException {
ArrayList<ProblemData> data = new ArrayList<>();
JSONObject jsonObject = jsondata;
JSONObject res = jsonObject.getJSONObject("result");
JSONArray problems = res.getJSONArray("problems");
JSONArray stats = res.getJSONArray("problemStatistics");
for(int i=0; i< stats.length() && i<20;i++){
JSONObject nxtprob = problems.getJSONObject(i);
JSONObject probstat = stats.getJSONObject(i);
int id = nxtprob.getInt("contestId");
String idx = nxtprob.getString("index");
String name = nxtprob.getString("name");
int solvecnt = probstat.getInt("solvedCount");
ProblemData dat = new ProblemData(id,idx,name,solvecnt);
data.add(dat);
}
return data;
}
示例4: execute
import org.json.JSONException; //導入依賴的package包/類
/**
* Executes the request and returns PluginResult.
*
* @param action The action to execute.
* @param args JSONArry of arguments for the plugin.
* @param callbackContext The callback id used when calling back into JavaScript.
* @return True if the action was valid, false if not.
*/
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if ("getDeviceInfo".equals(action)) {
JSONObject r = new JSONObject();
r.put("uuid", Device.uuid);
r.put("version", this.getOSVersion());
r.put("platform", this.getPlatform());
r.put("model", this.getModel());
r.put("manufacturer", this.getManufacturer());
r.put("isVirtual", this.isVirtual());
r.put("serial", this.getSerialNumber());
callbackContext.success(r);
}
else {
return false;
}
return true;
}
示例5: sendGetVideoSeriseListRequest
import org.json.JSONException; //導入依賴的package包/類
/**
*
* 3.6.1.獲取視頻係列
*
* @Description<功能詳細描述>
*
* @param task
* @param handler
* @param requestType
* @param maxId
* @param pagesize
* @return
* @LastModifiedDate:2016年10月10日
* @author wl
* @EditHistory:<修改內容><修改人>
*/
public static NetTask sendGetVideoSeriseListRequest(NetTask task, Handler handler, int requestType, String maxId,
String pagesize)
{
JSONObject bodyVaule = new JSONObject();
try
{
bodyVaule.put("maxId", maxId);
bodyVaule.put("pageSize", pagesize);
}
catch (JSONException e)
{
e.printStackTrace();
}
JSONObject requestObj =
NetRequestController.getPredefineObj("video", "VideoAdapter", "getVideoSeriseList", "general", bodyVaule);
return NetRequestController.sendStrBaseServlet(task, handler, requestType, requestObj);
}
示例6: getParent
import org.json.JSONException; //導入依賴的package包/類
/**
* Look up the parent DirectoryEntry containing this Entry.
* If this Entry is the root of its filesystem, its parent is itself.
*/
private JSONObject getParent(String baseURLstr) throws JSONException, IOException {
try {
LocalFilesystemURL inputURL = LocalFilesystemURL.parse(baseURLstr);
Filesystem fs = this.filesystemForURL(inputURL);
if (fs == null) {
throw new MalformedURLException("No installed handlers for this URL");
}
return fs.getParentForLocalURL(inputURL);
} catch (IllegalArgumentException e) {
MalformedURLException mue = new MalformedURLException("Unrecognized filesystem URL");
mue.initCause(e);
throw mue;
}
}
示例7: getParsedOsData
import org.json.JSONException; //導入依賴的package包/類
private JSONObject getParsedOsData() {
JSONObject osData = new JSONObject();
try {
//cpu
osData.put("cpu", getCpuInfo().toJson());
// vmstat
osData.put("vmstat", getVmstatInfo().toJson());
//meminfo
osData.put("meminfo", getMemInfoResource().toJson());
//battery
// TODO 권한 필요
//osData.put("battery", 10);
osData.put("battery", getBatteryPercent());
//network_usage
osData.put("network_usage", getNetworkUsageInfo().toJson());
} catch (JSONException e) {
e.printStackTrace();
}
return osData;
}
示例8: execute
import org.json.JSONException; //導入依賴的package包/類
@Override
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
if (action.equals("hide")) {
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
webView.postMessage("splashscreen", "hide");
}
});
} else if (action.equals("show")) {
cordova.getActivity().runOnUiThread(new Runnable() {
public void run() {
webView.postMessage("splashscreen", "show");
}
});
} else {
return false;
}
callbackContext.success();
return true;
}
示例9: sendAddCloudRequest
import org.json.JSONException; //導入依賴的package包/類
public static NetTask sendAddCloudRequest(NetTask task, Handler handler, int requestType, String content,
long createTime)
{
JSONObject bodyVaule = new JSONObject();
try
{
bodyVaule.put("content", content);
bodyVaule.put("createTime", "" + createTime);
}
catch (JSONException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
JSONObject requestObj =
NetRequestController.getPredefineObj("cloudevent",
"CloudEventAdapter",
"addCloudEvent",
"general",
bodyVaule);
return NetRequestController.sendStrBaseServlet(task, handler, requestType, requestObj);
}
示例10: serviceResolved
import org.json.JSONException; //導入依賴的package包/類
@Override
public void serviceResolved(ServiceEvent service) {
Log.i(TAG, "serviceResolved " + service);
if (service.getInfo().getNiceTextString().contains(SMARTCONFIG_IDENTIFIER)){
JSONObject deviceJSON = new JSONObject();
try {
deviceJSON.put("name", service.getName());
deviceJSON.put("host", service.getInfo().getHostAddresses()[0]);
deviceJSON.put("age", 0);
Log.i(TAG, "Publishing device found to application, name: " + service.getName());
callback.onDeviceResolved(deviceJSON);
} catch (JSONException e) {
e.printStackTrace();
}
}
}
示例11: toJSONString
import org.json.JSONException; //導入依賴的package包/類
@Override
public void toJSONString(JSONStringer stringer) throws JSONException {
for (Members element : QueryStatistics.Members.values()) {
try {
Field field = QueryStatistics.class.getDeclaredField(element.toString().toLowerCase());
if (element == Members.PARAM_HISTOGRAMS) {
stringer.key(element.name()).object();
for (Integer idx : this.param_histograms.keySet()) {
stringer.key(idx.toString()).object();
this.param_histograms.get(idx).toJSON(stringer);
stringer.endObject();
} // FOR
stringer.endObject();
// } else if (element == Members.PARAM_PROC_CORELATIONS) {
} else {
stringer.key(element.name()).value(field.get(this));
}
} catch (Exception ex) {
ex.printStackTrace();
System.exit(1);
}
} // FOR
}
示例12: getIdToken
import org.json.JSONException; //導入依賴的package包/類
private void getIdToken(final boolean forceRefresh, final CallbackContext callbackContext) throws JSONException {
cordova.getThreadPool().execute(new Runnable() {
@Override
public void run() {
FirebaseUser user = firebaseAuth.getCurrentUser();
if (user == null) {
callbackContext.error("User is not authorized");
} else {
user.getIdToken(forceRefresh)
.addOnCompleteListener(cordova.getActivity(), new OnCompleteListener<GetTokenResult>() {
@Override
public void onComplete(Task<GetTokenResult> task) {
if (task.isSuccessful()) {
callbackContext.success(task.getResult().getToken());
} else {
callbackContext.error(task.getException().getMessage());
}
}
});
}
}
});
}
開發者ID:chemerisuk,項目名稱:cordova-plugin-firebase-authentication,代碼行數:25,代碼來源:FirebaseAuthenticationPlugin.java
示例13: sendComfirmBookSchedule
import org.json.JSONException; //導入依賴的package包/類
/**
*
* 確認預約日程
*
* @Description<功能詳細描述>
*
* @param task
* @param handler
* @param requestType
* @param id
* @param status
* @return
* @LastModifiedDate:2016年11月22日
* @author wl
* @EditHistory:<修改內容><修改人>
*/
public static NetTask sendComfirmBookSchedule(NetTask task, Handler handler, int requestType, String id,
String status)
{
JSONObject requestObj = null;
try
{
JSONObject bodyVaule = new JSONObject();
bodyVaule.put("id", id);
bodyVaule.put("status", status);
requestObj =
NetRequestController.getPredefineObj("schedule",
"ScheduleAdapter",
"comfirmBookSchedule",
"general",
bodyVaule);
}
catch (JSONException e)
{
e.printStackTrace();
}
return NetRequestController.sendStrBaseServlet(task, handler, requestType, requestObj);
}
示例14: execute
import org.json.JSONException; //導入依賴的package包/類
@Override
public boolean execute(String action, CordovaArgs args, CallbackContext callbackContext) throws JSONException {
boolean cmdProcessed = true;
if (JSAction.INIT.equals(action)) {
jsInit(callbackContext);
} else if (JSAction.FETCH_UPDATE.equals(action)) {
jsFetchUpdate(callbackContext, args);
} else if (JSAction.INSTALL_UPDATE.equals(action)) {
jsInstallUpdate(callbackContext);
} else if (JSAction.CONFIGURE.equals(action)) {
jsSetPluginOptions(args, callbackContext);
} else if (JSAction.REQUEST_APP_UPDATE.equals(action)) {
jsRequestAppUpdate(args, callbackContext);
} else if (JSAction.IS_UPDATE_AVAILABLE_FOR_INSTALLATION.equals(action)) {
jsIsUpdateAvailableForInstallation(callbackContext);
} else if (JSAction.GET_VERSION_INFO.equals(action)) {
jsGetVersionInfo(callbackContext);
} else {
cmdProcessed = false;
}
return cmdProcessed;
}
示例15: getListValue
import org.json.JSONException; //導入依賴的package包/類
/**
* Return a list of strings with data from the field.
* @param jobj object
* @param name name
* @param field field
* @return list of strings
* @throws JSONException
*/
public static List<String> getListValue(JSONObject jobj, String name, String field)
throws JSONException {
if (jobj.isNull(name)) {
return Collections.emptyList();
} else {
JSONArray jArray = jobj.getJSONArray(name);
List<String> results = new ArrayList<>(jArray.length());
JSONObject object;
for (int i = 0; i < jArray.length(); i++) {
object = jArray.getJSONObject(i);
results.add(object.getString(field));
}
return results;
}
}