List of usage examples for org.json JSONObject getInt
public int getInt(String key) throws JSONException
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);//from w w w.j a v a 2s.c om 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:com.ymt.demo1.plates.hub.FireHubMainFragment.java
/** * hub??/* w w w.j a v a 2 s . c o m*/ */ public StringRequest hubPlateRequest() { return new StringRequest(BaseURLUtil.PLATE_REQUEST_URL, new Response.Listener<String>() { @Override public void onResponse(String s) { // Log.e("TAG", ">>>>>>>>>>>>>.s " + s); try { JSONObject jsonObject = new JSONObject(s); if (jsonObject.getInt("retCode") == 0) { //? JSONArray jsonArray = jsonObject.getJSONArray("data"); int length = jsonArray.length(); for (int i = 0; i < length; i++) { JSONObject object = jsonArray.getJSONObject(i); HubPlate hubPlate = new HubPlate(); hubPlate.setFid(object.getInt("fid")); hubPlate.setFup(object.getInt("fup")); hubPlate.setLastpost(object.getString("lastpost")); hubPlate.setName(object.getString("name")); hubPlate.setType(object.getString("type")); hubPlate.setRank(object.optInt("rank")); hubPlate.setThreads(object.optInt("threads")); plateList.add(hubPlate); } update1List(); } } catch (JSONException e) { AppContext.toastBadJson(); } } }, new Response.ErrorListener() { @Override public void onErrorResponse(VolleyError volleyError) { AppContext.toastBadInternet(); } }); }
From source file:net.geco.model.iojson.PersistentStore.java
public void importCourseSets(JSONStore store, Registry registry, Factory factory) throws JSONException { if (store.has(K.COURSESETS)) { // MIGR v2.x -> v2.2 JSONArray coursesets = store.getJSONArray(K.COURSESETS); for (int i = 0; i < coursesets.length(); i++) { JSONObject c = coursesets.getJSONObject(i); CourseSet courseset = store.register(factory.createCourseSet(), c.getInt(K.ID)); courseset.setName(c.getString(K.NAME)); registry.addCourseSet(courseset); }//from w ww . jav a 2 s .c o m } }
From source file:net.geco.model.iojson.PersistentStore.java
public void importCourses(JSONStore store, Registry registry, Factory factory) throws JSONException { JSONArray courses = store.getJSONArray(K.COURSES); for (int i = 0; i < courses.length(); i++) { JSONObject c = courses.getJSONObject(i); Course course = store.register(factory.createCourse(), c.getInt(K.ID)); course.setName(c.getString(K.NAME)); course.setLength(c.getInt(K.LENGTH)); course.setClimb(c.getInt(K.CLIMB)); course.setMassStartTime(new Date(c.optLong(K.START, TimeManager.NO_TIME_l))); // MIGR v2.x -> v2.2 course.setCourseSet(store.retrieve(c.optInt(K.COURSESET, 0), CourseSet.class)); JSONArray codez = c.getJSONArray(K.CODES); int[] codes = new int[codez.length()]; for (int j = 0; j < codes.length; j++) { codes[j] = codez.getInt(j);/*www .j a v a 2 s . c o m*/ } course.setCodes(codes); if (c.has(K.SECTIONS)) { JSONArray sectionz = c.getJSONArray(K.SECTIONS); for (int j = 0; j < sectionz.length(); j++) { JSONObject sectionTuple = sectionz.getJSONObject(j); Section section = store.register(factory.createSection(), sectionTuple.getInt(K.ID)); section.setStartIndex(sectionTuple.getInt(K.START_ID)); section.setName(sectionTuple.getString(K.NAME)); section.setType(SectionType.valueOf(sectionTuple.getString(K.TYPE))); section.setNeutralized(sectionTuple.optBoolean(K.NEUTRALIZED, false)); course.putSection(section); } course.refreshSectionCodes(); } registry.addCourse(course); } registry.ensureAutoCourse(factory); }
From source file:net.geco.model.iojson.PersistentStore.java
public void importCategories(JSONStore store, Registry registry, Factory factory) throws JSONException { JSONArray categories = store.getJSONArray(K.CATEGORIES); for (int i = 0; i < categories.length(); i++) { JSONObject c = categories.getJSONObject(i); Category category = store.register(factory.createCategory(), c.getInt(K.ID)); category.setName(c.getString(K.NAME)); category.setLongname(c.getString(K.LONG)); category.setCourse(store.retrieve(c.optInt(K.COURSE, 0), Course.class)); category.setCourseSet(store.retrieve(c.optInt(K.COURSESET, 0), CourseSet.class)); registry.addCategory(category);/*from www . ja v a 2 s .c om*/ } }
From source file:net.geco.model.iojson.PersistentStore.java
public void importClubs(JSONStore store, Registry registry, Factory factory) throws JSONException { JSONArray clubs = store.getJSONArray(K.CLUBS); for (int i = 0; i < clubs.length(); i++) { JSONObject c = clubs.getJSONObject(i); Club club = store.register(factory.createClub(), c.getInt(K.ID)); club.setName(c.getString(K.NAME)); club.setShortname(c.getString(K.SHORT)); registry.addClub(club);/*from w w w . j a va2s .co m*/ } }
From source file:net.geco.model.iojson.PersistentStore.java
public void importHeatSets(JSONStore store, Registry registry, Factory factory) throws JSONException { JSONArray heatsets = store.getJSONArray(K.HEATSETS); for (int i = 0; i < heatsets.length(); i++) { JSONObject h = heatsets.getJSONObject(i); HeatSet heatset = factory.createHeatSet(); heatset.setName(h.getString(K.NAME)); heatset.setQualifyingRank(h.getInt(K.RANK)); heatset.setSetType(ResultType.valueOf(h.getString(K.TYPE))); JSONArray heatz = h.getJSONArray(K.HEATS); String[] heats = new String[heatz.length()]; for (int j = 0; j < heats.length; j++) { heats[j] = heatz.getString(j); }//from www .ja v a 2s . c om heatset.setHeatNames(heats); JSONArray poolz = h.getJSONArray(K.POOLS); Pool[] pools = new Pool[poolz.length()]; for (int j = 0; j < pools.length; j++) { pools[j] = store.retrieve(poolz.getInt(j), Pool.class); } heatset.setSelectedPools(pools); registry.addHeatSet(heatset); } }
From source file:net.geco.model.iojson.PersistentStore.java
public void importRunnersData(JSONStore store, Registry registry, Factory factory) throws JSONException { final int I_RUNNER = 0; final int I_ECARD = 1; final int I_RESULT = 2; JSONArray runnersData = store.getJSONArray(K.RUNNERS_DATA); for (int i = 0; i < runnersData.length(); i++) { JSONArray runnerTuple = runnersData.getJSONArray(i); JSONObject c = runnerTuple.getJSONObject(I_RUNNER); Runner runner = factory.createRunner(); runner.setStartId(c.getInt(K.START_ID)); runner.setFirstname(c.getString(K.FIRST)); runner.setLastname(c.getString(K.LAST)); runner.setEcard(c.getString(K.ECARD)); runner.setClub(store.retrieve(c.getInt(K.CLUB), Club.class)); runner.setCategory(store.retrieve(c.getInt(K.CAT), Category.class)); runner.setCourse(store.retrieve(c.getInt(K.COURSE), Course.class)); runner.setRegisteredStarttime(new Date(c.getLong(K.START))); runner.setArchiveId((Integer) c.opt(K.ARK)); runner.setRentedEcard(c.optBoolean(K.RENT)); runner.setNC(c.optBoolean(K.NC)); registry.addRunner(runner);/*w ww .j a v a 2s. c o m*/ JSONObject d = runnerTuple.getJSONObject(I_ECARD); RunnerRaceData raceData = factory.createRunnerRaceData(); raceData.setStarttime(new Date(d.getLong(K.START))); raceData.setFinishtime(new Date(d.getLong(K.FINISH))); raceData.setControltime(new Date(d.getLong(K.CHECK))); raceData.setReadtime(new Date(d.getLong(K.READ))); JSONArray p = d.getJSONArray(K.PUNCHES); Punch[] punches = new Punch[p.length() / 2]; for (int j = 0; j < punches.length; j++) { punches[j] = factory.createPunch(); punches[j].setCode(p.getInt(2 * j)); punches[j].setTime(new Date(p.getLong(2 * j + 1))); } raceData.setPunches(punches); raceData.setRunner(runner); registry.addRunnerData(raceData); JSONObject r = runnerTuple.getJSONObject(I_RESULT); TraceData traceData = factory.createTraceData(); traceData.setNbMPs(r.getInt(K.MPS)); traceData.setNbExtraneous(r.optInt(K.EXTRA)); // MIGR v2.x -> v2.3 JSONArray t = r.getJSONArray(K.TRACE); Trace[] trace = new Trace[t.length() / 2]; for (int j = 0; j < trace.length; j++) { trace[j] = factory.createTrace(t.getString(2 * j), new Date(t.getLong(2 * j + 1))); } if (r.has(K.SECTION_DATA)) { SectionTraceData sectionData = (SectionTraceData) traceData; JSONArray sections = r.getJSONArray(K.SECTION_DATA); for (int j = 0; j < sections.length(); j++) { JSONArray section = sections.getJSONArray(j); sectionData.putSectionAt(store.retrieve(section.getInt(0), Section.class), section.getInt(1)); } } JSONArray neut = r.getJSONArray(K.NEUTRALIZED); for (int j = 0; j < neut.length(); j++) { trace[neut.getInt(j)].setNeutralized(true); } traceData.setTrace(trace); raceData.setTraceData(traceData); RunnerResult result = factory.createRunnerResult(); result.setRaceTime(r.optLong(K.RACE_TIME, TimeManager.NO_TIME_l)); // MIGR v2.x -> v2.2 result.setResultTime(r.getLong(K.TIME)); result.setStatus(Status.valueOf(r.getString(K.STATUS))); result.setTimePenalty(r.getLong(K.PENALTY)); result.setManualTimePenalty(r.optLong(K.MANUAL_PENALTY, 0)); // MIGR v2.x -> v2.3 raceData.setResult(result); } }
From source file:edu.pdx.its.portal.routelandia.entities.Highway.java
public Highway(JSONObject j) throws JSONException { this.highwayid = j.getInt("highwayid"); this.name = j.getString("highwayname"); }
From source file:org.sikuliserver.ExecuteSikuliAction.java
/** * Processes requests for both HTTP <code>GET</code> and <code>POST</code> * methods.//from w w w.j a va 2s. com * * @param request servlet request * @param response servlet response * @throws ServletException if a servlet-specific error occurs * @throws IOException if an I/O error occurs */ protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { /** * Check if picture folder exists to store the picture * If, not create it. */ File dir = new File("picture"); if (!dir.exists()) { dir.mkdir(); } else { FileUtils.cleanDirectory(new File("picture")); } String pictureName = new SimpleDateFormat("YYYY.MM.dd.HH.mm.ss.SSS").format(new Date()) + "."; PrintStream os = null; try { System.out.println(new SimpleDateFormat("HH:mm:ss.SSS").format(new Date()) + " INFO - Received: [Request from " + request.getServerName() + "]"); BufferedReader is = new BufferedReader(new InputStreamReader(request.getInputStream())); os = new PrintStream(response.getOutputStream()); String line = ""; StringBuilder sb = new StringBuilder(); while (!(line = is.readLine()).equals("|ENDS|")) { sb.append(line); } JSONObject obj = new JSONObject(sb.toString()); String action = obj.getString("action"); String picture = obj.getString("picture"); String text = obj.getString("text"); int defaultWait = obj.getInt("defaultWait"); String extension = obj.getString("pictureExtension"); String start = new SimpleDateFormat("HH:mm:ss.SSS").format(new Date()); long start_time = System.currentTimeMillis(); long end_time = start_time + defaultWait; System.out.println(defaultWait); byte[] data = Base64.decodeBase64(picture); pictureName += extension; String picturePath = "picture" + File.separator + pictureName; try (OutputStream stream = new FileOutputStream(picturePath)) { stream.write(data); } System.out.println(start + " INFO - Executing: [" + action + ": on picture " + picturePath + "]"); int actionResult = 0; SikuliAction sikuliAction = new SikuliAction(); boolean actionSuccess = false; while (System.currentTimeMillis() < end_time) { try { actionResult = sikuliAction.doAction(action, picturePath, text); if (actionResult == 1) { actionSuccess = true; break; } } catch (FindFailed ex) { System.out.println(new SimpleDateFormat("HH:mm:ss.SSS").format(new Date()) + " INFO - Element Not Found : " + ex); System.out.println(new SimpleDateFormat("HH:mm:ss.SSS").format(new Date()) + " INFO - Retrying again during " + (System.currentTimeMillis() - end_time) + "ms"); } System.out.println(new SimpleDateFormat("HH:mm:ss.SSS").format(new Date()) + " INFO - " + action + ": Still Waiting " + (System.currentTimeMillis() - end_time) + "ms"); } if (!actionSuccess) { System.out.println(new SimpleDateFormat("HH:mm:ss.SSS").format(new Date()) + " INFO - Element Not Found : " + picturePath); os.println("Failed"); os.println("|ENDR|"); } String end = new SimpleDateFormat("HH:mm:ss.SSS").format(new Date()); System.out.println(end + " INFO - Done [" + action + "] with result:" + actionResult); os.println(actionResult); os.println("|ENDR|"); } catch (IOException e) { System.out.println(new SimpleDateFormat("HH:mm:ss.SSS").format(new Date()) + " IOException : " + e); if (os != null) { os.println("Failed"); os.println("|ENDR|"); } } catch (JSONException ex) { System.out.println( new SimpleDateFormat("HH:mm:ss.SSS").format(new Date()) + " JSON Badly formated : " + ex); if (os != null) { os.println("Failed"); os.println("|ENDR|"); } } }