org.json.JSONException.toString()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(179)

本文整理了Java中org.json.JSONException.toString()方法的一些代码示例,展示了JSONException.toString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONException.toString()方法的具体详情如下:
包路径:org.json.JSONException
类名称:JSONException
方法名:toString

JSONException.toString介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

try {
   JSONArray jObj = new JSONArray(json);
 } catch (JSONException e) {
   Log.e("JSON Parser", "Error parsing data " + e.toString());
 }

代码示例来源:origin: stackoverflow.com

public class Main {

  public static int PRETTY_PRINT_INDENT_FACTOR = 4;
  public static String TEST_XML_STRING =
    "<?xml version=\"1.0\" ?><test attrib=\"moretest\">Turn this to JSON</test>";

  public static void main(String[] args) {
    try {
      JSONObject xmlJSONObj = XML.toJSONObject(TEST_XML_STRING);
      String jsonPrettyPrintString = xmlJSONObj.toString(PRETTY_PRINT_INDENT_FACTOR);
      System.out.println(jsonPrettyPrintString);
    } catch (JSONException je) {
      System.out.println(je.toString());
    }
  }
}

代码示例来源:origin: stackoverflow.com

protected void onPostExecute(Void v) {
    //parse JSON data
    try {
      JSONArray jArray = new JSONArray(result);    
      for(i=0; i < jArray.length(); i++) {

        JSONObject jObject = jArray.getJSONObject(i);

        String name = jObject.getString("name");
        String tab1_text = jObject.getString("tab1_text");
        int active = jObject.getInt("active");

      } // End Loop
      this.progressDialog.dismiss();
    } catch (JSONException e) {
      Log.e("JSONException", "Error: " + e.toString());
    } // catch (JSONException e)
  } // protected void onPostExecute(Void v)
} //class MyAsyncTask extends AsyncTask<String, String, Void>

代码示例来源:origin: google/physical-web

/**
  * Helper method to read an HTTP response.
  * @param is The InputStream.
  * @return An object representing the HTTP response.
  */
 protected JSONObject readInputStream(InputStream is) throws IOException {
  StringBuilder stringBuilder = new StringBuilder();
  BufferedReader in = new BufferedReader(new InputStreamReader(is, "UTF-8"));
  String line;
  while ((line = in.readLine()) != null) {
    stringBuilder.append(line);
  }
  JSONObject jsonObject;
  try {
    jsonObject = new JSONObject(stringBuilder.toString());
  } catch (JSONException error) {
    throw new IOException(error.toString());
  }
  return jsonObject;
 }
}

代码示例来源:origin: facebook/stetho

@Override
public boolean handleRequest(SocketLike socket, LightHttpRequest request, LightHttpResponse response) {
 String path = request.uri.getPath();
 try {
  if (PATH_VERSION.equals(path)) {
   handleVersion(response);
  } else if (PATH_PAGE_LIST.equals(path)) {
   handlePageList(response);
  } else if (PATH_ACTIVATE.equals(path)) {
   handleActivate(response);
  } else {
   response.code = HttpStatus.HTTP_NOT_IMPLEMENTED;
   response.reasonPhrase = "Not implemented";
   response.body = LightHttpBody.create("No support for " + path + "\n", "text/plain");
  }
 } catch (JSONException e) {
  response.code = HttpStatus.HTTP_INTERNAL_SERVER_ERROR;
  response.reasonPhrase = "Internal server error";
  response.body = LightHttpBody.create(e.toString() + "\n", "text/plain");
 }
 return true;
}

代码示例来源:origin: termux/termux-app

Toast.makeText(context, "Could not load the extra-keys property from the config: " + e.toString(), Toast.LENGTH_LONG).show();
Log.e("termux", "Error loading props", e);
mExtraKeys = new String[0][];

代码示例来源:origin: MorphiaOrg/morphia

@Override
  protected void describeMismatchSafely(final String item, final Description mismatchDescription) {
    try {
      Object itemAsPrettyJson = JSONParser.parseJSON(item);
      mismatchDescription.appendText("was ").appendValue(itemAsPrettyJson);
    } catch (final JSONException e) {
      throw new RuntimeException(String.format("Error parsing expected JSON string %s. Got Exception %s",
                           item, e.toString()));
    }
  }
}

代码示例来源:origin: MorphiaOrg/morphia

@Override
public void describeTo(final Description description) {
  try {
    Object expectedJsonAsPrettyJson = JSONParser.parseJSON(expectedJson);
    description.appendValue(expectedJsonAsPrettyJson);
  } catch (final JSONException e) {
    throw new RuntimeException(String.format("Error parsing expected JSON string %s. Got Exception %s",
                         expectedJson, e.toString()));
  }
}

代码示例来源:origin: facebook/stetho

@ChromeDevtoolsMethod
public JsonRpcResult getResponseBody(JsonRpcPeer peer, JSONObject params)
  throws JsonRpcException {
 try {
  String requestId = params.getString("requestId");
  return readResponseBody(requestId);
 } catch (IOException e) {
  throw new JsonRpcException(new JsonRpcError(JsonRpcError.ErrorCode.INTERNAL_ERROR,
    e.toString(),
    null /* data */));
 } catch (JSONException e) {
  throw new JsonRpcException(new JsonRpcError(JsonRpcError.ErrorCode.INTERNAL_ERROR,
    e.toString(),
    null /* data */));
 }
}

代码示例来源:origin: facebook/facebook-android-sdk

private void logEvent(
    String eventName,
    Double valueToSum,
    Bundle parameters,
    boolean isImplicitlyLogged,
    @Nullable final UUID currentSessionId) {
  try {
    AppEvent event = new AppEvent(
        this.contextName,
        eventName,
        valueToSum,
        parameters,
        isImplicitlyLogged,
        currentSessionId);
    logEvent(event, accessTokenAppId);
  } catch (JSONException jsonException) {
    // If any of the above failed, just consider this an illegal event.
    Logger.log(LoggingBehavior.APP_EVENTS, "AppEvents",
        "JSON encoding for app event failed: '%s'", jsonException.toString());
  } catch (FacebookException e) {
    // If any of the above failed, just consider this an illegal event.
    Logger.log(LoggingBehavior.APP_EVENTS, "AppEvents",
        "Invalid app event: %s", e.toString());
  }
}

代码示例来源:origin: facebook/stetho

public JSONObject dispatch(JsonRpcPeer peer, String methodName, @Nullable JSONObject params)
  throws JsonRpcException {
 MethodDispatchHelper dispatchHelper = findMethodDispatcher(methodName);
 if (dispatchHelper == null) {
  throw new JsonRpcException(new JsonRpcError(JsonRpcError.ErrorCode.METHOD_NOT_FOUND,
    "Not implemented: " + methodName,
    null /* data */));
 }
 try {
  return dispatchHelper.invoke(peer, params);
 } catch (InvocationTargetException e) {
  Throwable cause = e.getCause();
  ExceptionUtil.propagateIfInstanceOf(cause, JsonRpcException.class);
  throw ExceptionUtil.propagate(cause);
 } catch (IllegalAccessException e) {
  throw new RuntimeException(e);
 } catch (JSONException e) {
  throw new JsonRpcException(new JsonRpcError(JsonRpcError.ErrorCode.INTERNAL_ERROR,
    e.toString(),
    null /* data */));
 }
}

代码示例来源:origin: facebook/facebook-android-sdk

fail(errorMessage + e.toString());
} catch (JSONException e) {
  fail(errorMessage + e.toString());
} finally {
  if (stream != null) {

代码示例来源:origin: stackoverflow.com

JSONObject featureCollection = new JSONObject();
 try {
   featureCollection.put("type", "featureCollection");
   JSONArray featureList = new JSONArray();
   // iterate through your list
   for (ListElement obj : list) {
     // {"geometry": {"type": "Point", "coordinates": [-94.149, 36.33]}
     JSONObject point = new JSONObject();
     point.put("type", "Point");
     // construct a JSONArray from a string; can also use an array or list
     JSONArray coord = new JSONArray("["+obj.getLon()+","+obj.getLat()+"]");
     point.put("coordinates", coord);
     JSONObject feature = new JSONObject();
     feature.put("geometry", point);
     featureList.put(feature);
     featureCollection.put("features", featureList);
   }
 } catch (JSONException e) {
   Log.error("can't save json object: "+e.toString());
 }
 // output the result
 System.out.println("featureCollection="+featureCollection.toString());

代码示例来源:origin: stackoverflow.com

//try parse the string to a JSON object
try {
  jObj = new JSONObject(json);            
} catch (JSONException e) {
  Log.e("JSON Parser", "Error parsing data " + e.toString());
}

代码示例来源:origin: stackoverflow.com

//Parse string to JSON object
 try {
   jarray = new JSONObject(builder.toString());
 } catch (JSONException e) {
   Log.e("JSON Parser", "Error parsing data " + e.toString());
 }
 //Return json to array
 return jarray;

代码示例来源:origin: stackoverflow.com

try {
  jObj = new JSONArray(json);
} catch (JSONException e) {
  Log.e("JSON Parser", "Error parsing data " + e.toString());
}

代码示例来源:origin: stackoverflow.com

try {
   JSONArray ja = new JSONArray(buffer.toString());
   JSONArray innerJsonArray = ja.getJsonArray(0);
   JSONObject object = innerJsonArray.getJSONObject(0);
   String title = object.getString("title");                
  } 
  catch (JSONException e) {
   Log.e("JSON Parser", "Error parsing data " + e.toString());
  }

代码示例来源:origin: com.belerweb/weibo4j-oauth2

public static String[] constructIds(Response res) throws WeiboException {
 try {
  JSONArray list = res.asJSONObject().getJSONArray("ids");
  String temp = list.toString().substring(1, list.toString().length() - 1);
  String[] ids = temp.split(",");
  return ids;
 } catch (JSONException jsone) {
  throw new WeiboException(jsone.getMessage() + ":" + jsone.toString(), jsone);
 }
}

代码示例来源:origin: AmazMod/AmazMod

private void resetNotificationsCounter() {
  String data = Settings.System.getString(mContext.getContentResolver(), "CustomWatchfaceData");
  if (data == null || data.equals(""))
    Settings.System.putString(mContext.getContentResolver(), "CustomWatchfaceData", "{}");
  try {
    JSONObject json_data = new JSONObject(data);
    json_data.put("notifications", 0);
    Settings.System.putString(mContext.getContentResolver(), "CustomWatchfaceData", json_data.toString());
  } catch (JSONException e) {
    Log.e(Constants.TAG, "AmazModLauncher refreshMessages JSONException: " + e.toString());
  }
}

代码示例来源:origin: bitstadium/HockeySDK-Android

public void writeCrashReport(Context context) {
  File file = new File(context.getFilesDir(), crashIdentifier + ".stacktrace");
  try {
    writeCrashReport(file);
  } catch (JSONException e) {
    HockeyLog.error("Could not write crash report with error " + e.toString());
  }
}

相关文章