List of usage examples for org.json JSONException toString
public String toString()
From source file:com.cssweb.android.view.FinanceMini.java
public void drawPrice(Canvas canvas) { //canvas.restore(); Paint paint = this.mPaint; paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true);/*from ww w . j ava 2 s. co m*/ if (quoteData != null) { try { JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); paint.setTextAlign(Paint.Align.LEFT); paint.setTextSize(mTextSize); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); int syjd = jo.getInt("syjd"); switch (syjd) { case 1: canvas.drawText("()", x, y, paint); break; case 2: canvas.drawText("()", x, y, paint); break; case 3: canvas.drawText("()", x, y, paint); break; case 4: canvas.drawText("()", x, y, paint); break; default: canvas.drawText("", x, y, paint); break; } if (jo.getDouble("wb") < 0) paint.setColor(GlobalColor.colorPriceDown); else if (jo.getDouble("wb") > 0) paint.setColor(GlobalColor.colorpriceUp); else paint.setColor(GlobalColor.colorPriceEqual); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width / 2, -DY * 5); if (jo.getInt("tp") == 1) canvas.drawText("", x - tips, y, paint); else canvas.drawText(Utils.dataFormation(jo.getDouble("wb") * 100, 1) + "%", x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getInt("cjsl"), false), x - tips, y, paint); paint.setColor(GlobalColor.colorpriceUp); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("wp"), false), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("hs") * 100, 1) + "%", x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("jz"), 1), x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("mgsy"), 2), x - tips, y, paint); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, -DY * 5); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); if (NameRule.isBond(type)) canvas.drawText("", x, y, paint); else canvas.drawText("PE()", x, y, paint); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width / 2, -DY * 5); if (jo.getDouble("wc") < 0) { paint.setColor(GlobalColor.colorPriceDown); canvas.drawText("-" + Utils.getAmountFormat(Math.abs(jo.getDouble("wc")), true), x - tips, y, paint); } else if (jo.getDouble("wc") > 0) { paint.setColor(GlobalColor.colorpriceUp); canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), true), x - tips, y, paint); } else { paint.setColor(GlobalColor.colorPriceEqual); canvas.drawText(Utils.getAmountFormat(jo.getDouble("wc"), false), x - tips, y, paint); } paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("lb"), 1, jo.getInt("tp")), x - tips, y, paint); paint.setColor(GlobalColor.colorPriceDown); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("np"), false), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("gb"), true), x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("ltsl") * 100, true), x - tips, y, paint); canvas.translate(0, DY); if (NameRule.isBond(type)) { canvas.drawText(Utils.dataFormation(jo.getDouble("fullprice"), 1), x - tips, y, paint); } else { canvas.drawText(Utils.dataFormation(jo.getDouble("sy"), 1), x - tips, y, paint); } } catch (JSONException e) { Log.e(TAG, e.toString()); } } }
From source file:com.cssweb.android.view.FinanceMini.java
public void drawHKIndex(Canvas canvas) { Paint paint = this.mPaint; paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true);// w w w. j a v a2 s . c o m if (quoteData != null) { try { JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); paint.setTextAlign(Paint.Align.LEFT); paint.setTextSize(mTextSize); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); canvas.translate(0, DY); canvas.drawText("", x + tips, y, paint); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width, -DY * 3); paint.setColor(GlobalColor.colorpriceUp); canvas.translate(0, DY); canvas.drawText(String.valueOf(jo.getInt("zj")), x - tips, y, paint); paint.setColor(GlobalColor.colorPriceEqual); canvas.translate(0, DY); canvas.drawText(String.valueOf(jo.getInt("pj")), x - tips, y, paint); paint.setColor(GlobalColor.colorPriceDown); canvas.translate(0, DY); canvas.drawText(String.valueOf(jo.getInt("dj")), x - tips, y, paint); } catch (JSONException e) { Log.e(TAG, e.toString()); } } }
From source file:com.cssweb.android.view.FinanceMini.java
public void drawIndex(Canvas canvas) { //canvas.restore(); Paint paint = this.mPaint; paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true);// w w w . ja va 2 s . c o m if (quoteData != null) { try { JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); paint.setTextAlign(Paint.Align.LEFT); paint.setTextSize(mTextSize); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("???", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); paint.setTextAlign(Paint.Align.RIGHT); canvas.translate(width, -DY * 5); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("a"), true), x, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("b"), true), x, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("govbond"), true), x, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("fund"), true), x, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("warrant"), true), x, y, paint); canvas.translate(0, DY); paint.setColor(GlobalColor.colorStockName); canvas.drawText(Utils.getAmountFormat(jo.getDouble("bond"), true), x, y, paint); } catch (JSONException e) { Log.e(TAG, e.toString()); } } }
From source file:com.cssweb.android.view.FinanceMini.java
private void drawQihuo(Canvas canvas) { Paint paint = this.mPaint; paint.setTypeface(Typeface.DEFAULT_BOLD); paint.setAntiAlias(true);// w w w. ja v a 2s .c o m if (quoteData != null) { try { JSONArray jArr = quoteData.getJSONArray("data"); JSONObject jo = jArr.getJSONObject(0); paint.setTextAlign(Paint.Align.LEFT); paint.setTextSize(mTextSize); paint.setColor(GlobalColor.colorLabelName); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); // canvas.translate(0, DY); // canvas.drawText(" ", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); paint.setTextAlign(Paint.Align.RIGHT); paint.setColor(GlobalColor.colorStockName); canvas.translate(width / 2, -DY * 4); canvas.drawText(Utils.getAmountFormat(jo.getInt("cjsl"), false), x - tips, y, paint); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("jrjs"), stockdigit, jo.getInt("tp")), x - tips, y, paint); paint.setColor(GlobalColor.colorpriceUp); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("zt"), stockdigit, jo.getInt("tp")), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("jrcc"), 0, jo.getInt("tp")), x - tips, y, paint); // canvas.translate(0, DY); // canvas.drawText(Utils.dataFormation(jo.getDouble("jrkc"), 0), x-tips, y, paint); paint.setColor(GlobalColor.colorpriceUp); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("wp"), false), x, y, paint); canvas.translate(0, -DY * 4); paint.setTextAlign(Paint.Align.LEFT); paint.setColor(GlobalColor.colorLabelName); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(0, DY); canvas.drawText("?", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); // canvas.translate(0, DY); // canvas.drawText(" ", x, y, paint); canvas.translate(0, DY); canvas.drawText("", x, y, paint); canvas.translate(width / 2, -DY * 5); paint.setTextAlign(Paint.Align.RIGHT); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("cjje"), false), x - tips, y, paint); paint.setColor(GlobalColor.colorPriceEqual); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("zrjs"), stockdigit, jo.getInt("tp")), x - tips, y, paint); paint.setColor(GlobalColor.colorPriceDown); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("dt"), stockdigit, jo.getInt("tp")), x - tips, y, paint); paint.setColor(GlobalColor.colorStockName); canvas.translate(0, DY); canvas.drawText(Utils.dataFormation(jo.getDouble("zc"), 0, jo.getInt("tp")), x - tips, y, paint); // paint.setColor(GlobalColor.colorStockName); // canvas.translate(0, DY); // canvas.drawText(Utils.dataFormation(jo.getDouble("jrpc"), 0), x-tips, y, paint); paint.setColor(GlobalColor.colorPriceDown); canvas.translate(0, DY); canvas.drawText(Utils.getAmountFormat(jo.getDouble("np"), false), x - tips, y, paint); } catch (JSONException e) { Log.e(TAG, e.toString()); } } }
From source file:info.aamulumi.tomate.RequestSender.java
/** * Send HTTP Request with params (x-url-encoded) * * @param requestURL - URL of the request * @param method - HTTP method (GET, POST, PUT, DELETE, ...) * @param urlParameters - parameters send in URL * @param bodyParameters - parameters send in body (encoded) * @return JSONObject returned by the server *//*from ww w. j a v a2s. c om*/ public JSONObject makeHttpRequest(String requestURL, String method, HashMap<String, String> urlParameters, HashMap<String, String> bodyParameters) { HttpURLConnection connection = null; URL url; JSONObject jObj = null; try { // Check if we must add parameters in URL if (urlParameters != null) { String stringUrlParams = getFormattedParameters(urlParameters); url = new URL(requestURL + "?" + stringUrlParams); } else url = new URL(requestURL); // Create connection connection = (HttpURLConnection) url.openConnection(); // Add cookies to request if (mCookieManager.getCookieStore().getCookies().size() > 0) connection.setRequestProperty("Cookie", TextUtils.join(";", mCookieManager.getCookieStore().getCookies())); // Set request parameters connection.setReadTimeout(5000); connection.setConnectTimeout(5000); connection.setRequestMethod(method); connection.setDoInput(true); // Check if we must add parameters in body if (bodyParameters != null) { // Create a string with parameters String stringBodyParameters = getFormattedParameters(bodyParameters); // Set output request parameters connection.setDoOutput(true); connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); connection.setRequestProperty("Content-Length", "" + Integer.toString(stringBodyParameters.getBytes().length)); connection.setRequestProperty("Content-Language", "fr-FR"); // Send body's request OutputStream os = connection.getOutputStream(); BufferedWriter writer = new BufferedWriter(new OutputStreamWriter(os, "UTF-8")); writer.write(stringBodyParameters); writer.flush(); writer.close(); os.close(); } // Get response code int responseCode = connection.getResponseCode(); // If response is 200 (OK) if (responseCode == HttpsURLConnection.HTTP_OK) { // Keep new cookies in the manager List<String> cookiesHeader = connection.getHeaderFields().get(COOKIES_HEADER); if (cookiesHeader != null) { for (String cookie : cookiesHeader) mCookieManager.getCookieStore().add(null, HttpCookie.parse(cookie).get(0)); } // Read the response String line; BufferedReader br = new BufferedReader(new InputStreamReader(connection.getInputStream())); StringBuilder sb = new StringBuilder(); while ((line = br.readLine()) != null) { sb.append(line).append("\n"); } // Parse the response to a JSON Object try { jObj = new JSONObject(sb.toString()); } catch (JSONException e) { Log.d("JSON Parser", "Error parsing data " + e.toString()); Log.d("JSON Parser", "Setting value of jObj to null"); jObj = null; } } else { Log.w("HttpUrlConnection", "Error : server sent code : " + responseCode); } } catch (MalformedURLException e) { Log.e("Network", "Error in URL"); e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } finally { // Close connection if (connection != null) connection.disconnect(); } return jObj; }
From source file:com.krayzk9s.imgurholo.ui.AccountFragment.java
public void onGetObject(Object data, String tag) { refreshedCount++;//w w w .jav a 2 s .c o m if (refreshedCount == 5) { mPullToRefreshLayout.setRefreshComplete(); } try { if (data == null) { return; } JSONObject jsonData; /*int duration = Toast.LENGTH_SHORT; Toast toast; MainActivity activity = (MainActivity) getActivity(); toast = Toast.makeText(activity, "User not found", duration); toast.show(); activity.getFragmentManager().popBackStack();*/ if (tag.equals(ACCOUNTDATA)) { jsonData = ((JSONObject) data).getJSONObject("data"); if (jsonData.has("error")) return; Calendar accountCreationDate = Calendar.getInstance(); accountCreationDate.setTimeInMillis((long) jsonData.getInt("created") * 1000); SimpleDateFormat sdf = new SimpleDateFormat("MM/dd/yyyy"); String accountcreated = sdf.format(accountCreationDate.getTime()); created.setText(accountcreated); reputation.setText(Integer.toString(jsonData.getInt("reputation"))); if (jsonData.getString("bio") != null && !jsonData.getString("bio").equals("null") && !jsonData.getString("bio").equals("")) biography.setText(jsonData.getString("bio")); else biography.setText("No Biography"); } else if (tag.equals(COUNTDATA)) { jsonData = ((JSONObject) data); if (jsonData.has("error")) return; if (jsonData.getInt("status") == 200) mMenuList[1] = mMenuList[1] + " (" + Integer.toString(jsonData.getInt("data")) + ")"; else mMenuList[1] = mMenuList[1] + " (0)"; } else if (tag.equals(ALBUMDATA)) { jsonData = ((JSONObject) data); if (jsonData.has("error")) return; if (jsonData.getInt("status") == 200) mMenuList[0] = mMenuList[0] + " (" + Integer.toString(jsonData.getJSONArray("data").length()) + ")"; else mMenuList[0] = mMenuList[0] + " (0)"; } else if (tag.equals(LIKEDATA)) { JSONArray jsonArray = ((JSONObject) data).getJSONArray("data"); mMenuList[2] = mMenuList[2] + " (" + String.valueOf(jsonArray.length()) + ")"; } else if (tag.equals(COMMENTDATA)) { jsonData = ((JSONObject) data); mMenuList[3] = mMenuList[3] + " (" + String.valueOf(jsonData.getInt("data")) + ")"; } adapter.notifyDataSetChanged(); } catch (JSONException e) { Log.e("Error!", e.toString()); } }
From source file:cn.code.notes.gtask.data.TaskList.java
public JSONObject getCreateAction(int actionId) { JSONObject js = new JSONObject(); try {/*www . j a v a2 s . com*/ // action_type js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, GTaskStringUtils.GTASK_JSON_ACTION_TYPE_CREATE); // action_id js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId); // index js.put(GTaskStringUtils.GTASK_JSON_INDEX, mIndex); // entity_delta JSONObject entity = new JSONObject(); entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName()); entity.put(GTaskStringUtils.GTASK_JSON_CREATOR_ID, "null"); entity.put(GTaskStringUtils.GTASK_JSON_ENTITY_TYPE, GTaskStringUtils.GTASK_JSON_TYPE_GROUP); js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity); } catch (JSONException e) { Log.e(TAG, e.toString()); e.printStackTrace(); throw new ActionFailureException("fail to generate tasklist-create jsonobject"); } return js; }
From source file:cn.code.notes.gtask.data.TaskList.java
public JSONObject getUpdateAction(int actionId) { JSONObject js = new JSONObject(); try {/*w ww .ja va 2 s. c o m*/ // action_type js.put(GTaskStringUtils.GTASK_JSON_ACTION_TYPE, GTaskStringUtils.GTASK_JSON_ACTION_TYPE_UPDATE); // action_id js.put(GTaskStringUtils.GTASK_JSON_ACTION_ID, actionId); // id js.put(GTaskStringUtils.GTASK_JSON_ID, getGid()); // entity_delta JSONObject entity = new JSONObject(); entity.put(GTaskStringUtils.GTASK_JSON_NAME, getName()); entity.put(GTaskStringUtils.GTASK_JSON_DELETED, getDeleted()); js.put(GTaskStringUtils.GTASK_JSON_ENTITY_DELTA, entity); } catch (JSONException e) { Log.e(TAG, e.toString()); e.printStackTrace(); throw new ActionFailureException("fail to generate tasklist-update jsonobject"); } return js; }
From source file:cn.code.notes.gtask.data.TaskList.java
public void setContentByRemoteJSON(JSONObject js) { if (js != null) { try {//w w w .j a v a 2 s . c o m // id if (js.has(GTaskStringUtils.GTASK_JSON_ID)) { setGid(js.getString(GTaskStringUtils.GTASK_JSON_ID)); } // last_modified if (js.has(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)) { setLastModified(js.getLong(GTaskStringUtils.GTASK_JSON_LAST_MODIFIED)); } // name if (js.has(GTaskStringUtils.GTASK_JSON_NAME)) { setName(js.getString(GTaskStringUtils.GTASK_JSON_NAME)); } } catch (JSONException e) { Log.e(TAG, e.toString()); e.printStackTrace(); throw new ActionFailureException("fail to get tasklist content from jsonobject"); } } }
From source file:cn.code.notes.gtask.data.TaskList.java
public void setContentByLocalJSON(JSONObject js) { if (js == null || !js.has(GTaskStringUtils.META_HEAD_NOTE)) { Log.w(TAG, "setContentByLocalJSON: nothing is avaiable"); }// www .j a v a 2 s.c o m try { JSONObject folder = js.getJSONObject(GTaskStringUtils.META_HEAD_NOTE); if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_FOLDER) { String name = folder.getString(NoteColumns.SNIPPET); setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + name); } else if (folder.getInt(NoteColumns.TYPE) == Notes.TYPE_SYSTEM) { if (folder.getLong(NoteColumns.ID) == Notes.ID_ROOT_FOLDER) setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_DEFAULT); else if (folder.getLong(NoteColumns.ID) == Notes.ID_CALL_RECORD_FOLDER) setName(GTaskStringUtils.MIUI_FOLDER_PREFFIX + GTaskStringUtils.FOLDER_CALL_NOTE); else Log.e(TAG, "invalid system folder"); } else { Log.e(TAG, "error type"); } } catch (JSONException e) { Log.e(TAG, e.toString()); e.printStackTrace(); } }