List of usage examples for org.json JSONArray get
public Object get(int index) throws JSONException
From source file:com.facebook.samples.sessionlogin.LoginUsingActivityActivity.java
public void getFrinedsBirthDays() { Session session = Session.getActiveSession(); //Session.NewPermissionsRequest newPermissionsRequest=new Session.NewPermissionsRequest(this,Arrays.asList("friends_birthday")); //session.requestNewReadPermissions(newPermissionsRequest); String fqlQuery = "select uid, name,birthday, is_app_user from user where uid in (select uid2 from friend where uid1 = me())"; Bundle params = new Bundle(); params.putString("q", fqlQuery); session = Session.getActiveSession(); com.facebook.Request request = new com.facebook.Request(session, "/fql", params, HttpMethod.GET, new com.facebook.Request.Callback() { @Override/*from ww w . java 2 s . c o m*/ public void onCompleted(Response response) { try { GraphObject go = response.getGraphObject(); JSONObject jso = go.getInnerJSONObject(); JSONArray jarray = jso.getJSONArray("data"); for (int i = 0; i < jarray.length(); i++) { JSONObject jObject = (JSONObject) jarray.get(i); list.add(jObject.getString("name") + jObject.get("birthday")); Log.v("info", jObject.getString("name") + jObject.get("birthday")); } } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } Log.v("birthdays", response.toString()); showDialog(); } }); com.facebook.Request.executeBatchAsync(request); }
From source file:net.freifunk.android.discover.model.NodesResponse.java
@Override public void onResponse(JSONObject jsonObject) { try {//from w w w . jav a 2s.co m JSONArray node_list = jsonObject.getJSONArray("nodes"); for (int i = 0; i < node_list.length(); i++) { JSONObject node = node_list.getJSONObject(i); List<String> mac_list = new ArrayList<String>(1); // MAC if (node.has("macs")) { String[] macs = ((String) node.get("macs")).split(","); mac_list = new ArrayList<String>(macs.length); for (String mac : macs) { mac_list.add(mac.trim()); } } else { mac_list.add(" "); } // Name String name = ((String) node.get("name")).trim(); // Firmware String firmware = String.valueOf(node.get("firmware")).trim(); // Flags Map<String, String> flags = new HashMap<String, String>(); JSONObject jflags = node.getJSONObject("flags"); Iterator flag = jflags.keys(); while (flag.hasNext()) { String key = (String) flag.next(); String val = String.valueOf(jflags.get(key)); flags.put(key, val); } // Geo LatLng pos = null; // Log.d(TAG, String.valueOf(node.get("geo"))); if (!String.valueOf(node.get("geo")).equals("null")) { JSONArray geo = node.getJSONArray("geo"); Double lat = (Double) geo.get(0); Double lng = (Double) geo.get(1); pos = new LatLng(lat, lng); } // Id String id = ((String) node.get("id")).trim(); Node n = new Node(mac_list, this.mCallingMap.getMapName(), name, firmware, flags, pos, id); Node.nodes.add(n); mCallback.onNodeAvailable(n); } } catch (JSONException e) { Log.e(TAG, "Seems something went wrong while loading Nodes for " + this.mCallingMap.getMapName() + ":" + e.toString()); } finally { mCallback.onResponseFinished(this.mCallingMap); } }
From source file:edu.umass.cs.msocket.proxy.console.commands.StartWatchdog.java
@Override public void parse(String commandText) throws Exception { if (module.getProxyGroupGuid() == null) { console.printString("You have to connect to a proxy group first.\n"); return;// w ww .j ava 2 s .co m } // Check if we already have a watchdog with that name running try { StringTokenizer st = new StringTokenizer(commandText); if (st.countTokens() != 5) { console.printString("Bad number of arguments (expected 5 instead of " + st.countTokens() + ")\n"); return; } String targetList = st.nextToken(); String watchdogName = st.nextToken(); long lookupIntervalInMs = Long.parseLong(st.nextToken()); long suspiciousTimeoutInMs = Long.parseLong(st.nextToken()); long failureTimeoutInMs = Long.parseLong(st.nextToken()); if (!"proxy".equalsIgnoreCase(targetList) && !"location".equalsIgnoreCase(targetList) && !"watchdog".equalsIgnoreCase(targetList) && !"all".equalsIgnoreCase(targetList)) { console.printString( "Invalid list '" + targetList + "'. You must pick one of proxy, location, watchdog or all"); return; } if (suspiciousTimeoutInMs <= 0 || failureTimeoutInMs <= 0 || failureTimeoutInMs < suspiciousTimeoutInMs) { console.printString( "Timeouts must have positive values and failure timeout must be greater than suspicious timeout."); return; } if (lookupIntervalInMs <= 0) { console.printString("Lookup interval must be a positive number."); return; } if (!module.isSilent()) console.printString("Looking for watchdog " + watchdogName + " GUID and certificates...\n"); GuidEntry myGuid = KeyPairUtils.getGuidEntryFromPreferences( module.getGnsClient().getGnsHost() + ":" + module.getGnsClient().getGnsPort(), watchdogName); final UniversalGnsClient gnsClient = module.getGnsClient(); if (myGuid == null) { if (!module.isSilent()) console.printString( "No keys found for watchdog " + watchdogName + ". Generating new GUID and keys\n"); myGuid = gnsClient.guidCreate(module.getAccountGuid(), watchdogName); } if (myGuid == null) { console.printString( "No keys found for watchdog " + watchdogName + ". Cannot connect without the key\n"); return; } if (!module.isSilent()) console.printString("Watchdog has guid " + myGuid.getGuid()); // Make sure we advertise ourselves as a watchdog (readable for everyone) gnsClient.fieldReplaceOrCreate(myGuid.getGuid(), GnsConstants.SERVICE_TYPE_FIELD, new JSONArray().put(GnsConstants.WATCHDOG_SERVICE), myGuid); gnsClient.aclAdd(AccessType.READ_WHITELIST, myGuid, GnsConstants.SERVICE_TYPE_FIELD, null); // Check if we are a member of the group final String groupGuid = module.getProxyGroupGuid().getGuid(); JSONArray members = gnsClient.groupGetMembers(groupGuid, myGuid); boolean isVerified = false; for (int i = 0; i < members.length(); i++) { if (myGuid.getGuid().equals(members.get(i))) { isVerified = true; break; } } if (!isVerified) { console.printString( "This watchdog has not been verified yet, it will stay in the unverified list until it gets added to the proxy group"); } // And now start 3 watchdogs: 1 for proxies, 1 for location services and 1 // for other watchdogs if ("proxy".equalsIgnoreCase(targetList) || "all".equalsIgnoreCase(targetList)) { Watchdog proxyWatchdog = new Watchdog(gnsClient, myGuid, groupGuid, lookupIntervalInMs, GnsConstants.ACTIVE_PROXY_FIELD, GnsConstants.SUSPICIOUS_PROXY_FIELD, GnsConstants.INACTIVE_PROXY_FIELD, suspiciousTimeoutInMs, failureTimeoutInMs); module.setRunningProxyWatchdog(proxyWatchdog); proxyWatchdog.start(); } if ("location".equalsIgnoreCase(targetList) || "all".equalsIgnoreCase(targetList)) { Watchdog locationWatchdog = new Watchdog(gnsClient, myGuid, groupGuid, lookupIntervalInMs, GnsConstants.ACTIVE_LOCATION_FIELD, GnsConstants.SUSPICIOUS_LOCATION_FIELD, GnsConstants.INACTIVE_LOCATION_FIELD, suspiciousTimeoutInMs, failureTimeoutInMs); module.setRunningLocationWatchdog(locationWatchdog); locationWatchdog.start(); } if ("watchdog".equalsIgnoreCase(targetList) || "all".equalsIgnoreCase(targetList)) { Watchdog watchdogWatchdog = new Watchdog(gnsClient, myGuid, groupGuid, lookupIntervalInMs, GnsConstants.ACTIVE_WATCHDOG_FIELD, GnsConstants.SUSPICIOUS_WATCHDOG_FIELD, GnsConstants.INACTIVE_WATCHDOG_FIELD, suspiciousTimeoutInMs, failureTimeoutInMs); module.setRunningWatchdogWatchdog(watchdogWatchdog); watchdogWatchdog.start(); } } catch (Exception e) { console.printString("Failed to coonect to start watchdog service ( " + e + ")\n"); } }
From source file:com.andrew67.ddrfinder.adapters.MapLoaderV1.java
@Override protected ApiResult doInBackground(LatLngBounds... boxes) { // Fetch machine data in JSON format JSONArray jArray = new JSONArray(); try {//from w w w . j a v a 2 s .co m if (boxes.length == 0) throw new IllegalArgumentException("No boxes passed to doInBackground"); final LatLngBounds box = boxes[0]; final OkHttpClient client = new OkHttpClient(); final String LOADER_API_URL = sharedPref.getString(SettingsActivity.KEY_PREF_API_URL, ""); final HttpUrl requestURL = HttpUrl.parse(LOADER_API_URL).newBuilder() .addQueryParameter("source", "android") .addQueryParameter("latupper", "" + box.northeast.latitude) .addQueryParameter("longupper", "" + box.northeast.longitude) .addQueryParameter("latlower", "" + box.southwest.latitude) .addQueryParameter("longlower", "" + box.southwest.longitude).build(); Log.d("api", "Request URL: " + requestURL); final Request get = new Request.Builder().header("User-Agent", BuildConfig.APPLICATION_ID + " " + BuildConfig.VERSION_NAME + "/Android?SDK=" + Build.VERSION.SDK_INT).url(requestURL).build(); final Response response = client.newCall(get).execute(); final int statusCode = response.code(); Log.d("api", "Status code: " + statusCode); // Data loaded OK if (statusCode == 200) { final String jResponse = response.body().string(); Log.d("api", "Raw API result: " + jResponse); jArray = new JSONArray(jResponse); } // Code used for invalid parameters; in this case exceeding // the limits of the boundary box else if (statusCode == 400) { return new ApiResultV1(ApiResultV1.ERROR_ZOOM); } // Unexpected error code else { return new ApiResultV1(ApiResultV1.ERROR_API); } } catch (Exception e) { e.printStackTrace(); } // Return list ArrayList<ArcadeLocation> out = new ArrayList<>(); try { for (int i = 0; i < jArray.length(); ++i) { final JSONObject obj = (JSONObject) jArray.get(i); final String name = obj.getString("name"); boolean closed = false; if (ArcadeLocation.CLOSED.matcher(name).matches()) { closed = true; } // Fields added after ddr-finder 1.0 API should be // explicitly tested for, in order to maintain // compatibility with deployments of older versions boolean hasDDR = false; if (obj.has("hasDDR") && obj.getInt("hasDDR") == 1) { hasDDR = true; } out.add(new ArcadeLocationV1(obj.getInt("id"), name, obj.getString("city"), new LatLng(obj.getDouble("latitude"), obj.getDouble("longitude")), hasDDR, closed)); } } catch (Exception e) { out.clear(); } return new ApiResultV1(out, boxes[0]); }
From source file:io.teak.sdk.Helpers.java
private static List<Object> toList(JSONArray array) throws JSONException { List<Object> list = new ArrayList<>(); for (int i = 0; i < array.length(); i++) { Object value = array.get(i); if (value instanceof JSONArray) { value = toList((JSONArray) value); } else if (value instanceof JSONObject) { value = toMap((JSONObject) value); }//ww w .j a v a2 s . c o m list.add(value); } return list; }
From source file:com.google.samples.apps.iosched.feedback.FeedbackHelper.java
/** * Converts the feedback data from a {@link com.google.android.gms.wearable.DataMap} to a * {@link SessionFeedbackModel.SessionFeedbackData}; * * The {@code data} is a JSON string. The format of a typical response is: * <pre>[{"s":"sessionId-1234"},{"q":1,"a":2},{"q":0,"a":1},{"q":3,"a":1},{"q":2,"a":1}]</pre> * * @return SessionFeedbackData object, or null if JSON Parsing error */// w w w .j a v a2 s .c om public static SessionFeedbackData convertDataMapToFeedbackData(DataMap data) { try { if (data == null) { LOGE(TAG, "Failed to parse session data, DataMap is null"); return null; } String jsonString = data.getString("response"); if (TextUtils.isEmpty(jsonString)) { LOGE(TAG, "Failed to parse session data, empty json string"); return null; } LOGD(TAG, "jsonString is: " + jsonString); JSONArray jsonArray = new JSONArray(jsonString); if (jsonArray.length() > 0) { JSONObject sessionObj = (JSONObject) jsonArray.get(0); String sessionId = sessionObj.getString("s"); int[] answers = new int[4]; for (int i = 0; i < answers.length; i++) { answers[i] = -1; } for (int i = 1; i < jsonArray.length(); i++) { JSONObject answerObj = (JSONObject) jsonArray.get(i); int question = answerObj.getInt("q"); int answer = answerObj.getInt("a") + 1; answers[question] = answer; } return new SessionFeedbackData(sessionId, answers[0], answers[1], answers[2], answers[3], null); } } catch (JSONException e) { LOGE(TAG, "Failed to parse the json received from the wear", e); } return null; }
From source file:org.wso2.carbon.connector.integration.test.shopify.ShopifyConnectorIntegrationTest.java
/** * Positive test case for listOrders method with mandatory parameters. *///from www.j a v a 2s . c o m @Test(priority = 1, groups = { "wso2.esb" }, dependsOnMethods = { "testCreateOrderNegativeCase" }, description = "Shopify {listOrders} integration test with mandatory parameters.") public void listOrdersWithMandatoryParameters() throws Exception { esbRequestHeadersMap.put("Action", "urn:listOrders"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listOrders_mandatory.json"); JSONArray esbResponseArray = esbRestResponse.getBody().getJSONArray("orders"); String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/admin/orders.json"; RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap); JSONArray apiResponseArray = apiRestResponse.getBody().getJSONArray("orders"); Assert.assertEquals(esbResponseArray.length(), apiResponseArray.length()); if (esbResponseArray.length() > 0) { Assert.assertEquals(esbResponseArray.getJSONObject(0).get("id").toString(), apiResponseArray.getJSONObject(0).get("id").toString()); Assert.assertEquals(esbResponseArray.getJSONObject(0).get("name").toString(), apiResponseArray.getJSONObject(0).get("name").toString()); } else { Assert.assertTrue(false); } }
From source file:org.wso2.carbon.connector.integration.test.shopify.ShopifyConnectorIntegrationTest.java
/** * Positive test case for listOrders method with optional parameters. *//* w w w.j av a 2 s.c o m*/ @Test(priority = 1, groups = { "wso2.esb" }, dependsOnMethods = { "listOrdersWithMandatoryParameters" }, description = "Shopify {listOrders} integration test with optional parameters.") public void listOrdersWithOptionalParameters() throws Exception { esbRequestHeadersMap.put("Action", "urn:listOrders"); RestResponse<JSONObject> esbRestResponse = sendJsonRestRequest(proxyUrl, "POST", esbRequestHeadersMap, "esb_listOrders_optional.json"); JSONArray esbResponseArray = esbRestResponse.getBody().getJSONArray("orders"); String apiEndPoint = connectorProperties.getProperty("apiUrl") + "/admin/orders.json" + "?fields=email,financial_status"; RestResponse<JSONObject> apiRestResponse = sendJsonRestRequest(apiEndPoint, "GET", apiRequestHeadersMap); JSONArray apiResponseArray = apiRestResponse.getBody().getJSONArray("orders"); Assert.assertEquals(esbResponseArray.length(), apiResponseArray.length()); if (esbResponseArray.length() > 0) { Assert.assertEquals(esbResponseArray.getJSONObject(0).get("email").toString(), apiResponseArray.getJSONObject(0).get("email").toString()); Assert.assertEquals(esbResponseArray.getJSONObject(0).get("financial_status").toString(), apiResponseArray.getJSONObject(0).get("financial_status").toString()); Assert.assertFalse(esbResponseArray.getJSONObject(0).has("id")); Assert.assertFalse(apiResponseArray.getJSONObject(0).has("id")); } else { Assert.assertTrue(false); } }
From source file:com.vishnuvalleru.travelweatheralertsystem.MainActivity.java
private Vector<String> getWeatherInfo(LatLng point) { Vector<String> vct = new Vector<String>(); try {/*from w ww .j ava 2s . c o m*/ JSONObject jsonResponse = JSONReader .readJsonFromUrl("http://api.openweathermap.org/data/2.5/weather?lat=" + String.valueOf(point.latitude) + "&lon=" + String.valueOf(point.longitude)); JSONArray tempArr = (JSONArray) jsonResponse.get("weather"); JSONObject tempJson = (JSONObject) jsonResponse.get("main"); String wTemp = tempJson.getString("temp"); int dTemp = (int) ((Double.valueOf(wTemp) - 273) * 1.8 + 32); vct.add(String.valueOf(dTemp)); vct.add(tempJson.getString("humidity")); JSONObject jsonWeather = (JSONObject) tempArr.get(0); vct.add(jsonWeather.get("description").toString()); vct.add(jsonResponse.get("name").toString()); //adding elements to the end } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (JSONException e) { // TODO Auto-generated catch block e.printStackTrace(); } return vct; }
From source file:com.cssweb.android.view.TrendView.java
private void repairData() throws JSONException { close = quoteData.getDouble("close"); high = quoteData.getDouble("high"); low = quoteData.getDouble("low"); jrkp = quoteData.getDouble("jrkp"); Date dt = new Date(); int year = dt.getYear(); int month = dt.getMonth(); int day = dt.getDate(); int hour = dt.getHours(); int minute = dt.getMinutes(); JSONArray list = quoteData.getJSONArray("data"); if (quoteData.getString("quotetime") != null && !quoteData.getString("quotetime").equals("")) { year = Integer.parseInt(quoteData.getString("quotetime").substring(0, 4)); month = Integer.parseInt(quoteData.getString("quotetime").substring(5, 7)) - 1; day = Integer.parseInt(quoteData.getString("quotetime").substring(8, 10)); hour = Integer.parseInt(quoteData.getString("quotetime").substring(11, 13)); minute = Integer.parseInt(quoteData.getString("quotetime").substring(14, 16)); dt = new Date(year, month, day, hour, minute); }//from www .j a v a 2 s .c o m JSONArray jsonArray = new JSONArray(); if ("hk".equals(exchange)) { this.MINUTES = 300; Date dt1 = new Date(year, month, day, 9, 30); Date dt2 = new Date(year, month, day, 12, 0); Date dt3 = new Date(year, month, day, 13, 31); Date dt4 = new Date(year, month, day, 16, 0); long hopelen = 0; if (dt.getTime() < dt1.getTime()) { // 0 ? hopelen = 0; } if (dt.getTime() >= dt1.getTime() && dt.getTime() < dt2.getTime()) { hopelen = (dt.getTime() - dt1.getTime()) / 1000 / 60 + 1; } if (dt.getTime() >= dt2.getTime() && dt.getTime() < dt3.getTime()) { hopelen = 151; } if (dt.getTime() >= dt3.getTime() && dt.getTime() < dt4.getTime()) { hopelen = 151 + (dt.getTime() - dt3.getTime()) / 1000 / 60 + 1; } if (dt.getTime() >= dt4.getTime()) { hopelen = 301; } //?9.15 9.25 if (quoteData.getString("quotetime") == "null" || quoteData.getString("quotetime").equals("")) { hopelen = 1; } String time = ""; for (int i = 0; i < hopelen; i++) { if (i < 151) { time = Utils.format(new Date(dt1.getTime() + 1000 * 60 * i)); } if (i >= 151 && i <= 301) { time = Utils.format(new Date(dt3.getTime() + 1000 * 60 * (i - 151))); } Boolean flag = false; JSONArray json = new JSONArray(); for (int j = 0; j < list.length(); j++) { if (list.getJSONArray(j).getString(3).equals(time)) { json.put(0, list.getJSONArray(j).getDouble(0)); json.put(1, list.getJSONArray(j).getDouble(1)); json.put(2, list.getJSONArray(j).getDouble(2)); json.put(3, list.getJSONArray(j).getString(3)); json.put(4, 1);//?? if (i == 0) { json.put(5, list.getJSONArray(j).getDouble(1));//?? json.put(6, list.getJSONArray(j).getDouble(2));//?? } else { if (jsonArray.getJSONArray(i - 1).getInt(4) == 1) { json.put(5, list.getJSONArray(j).getDouble(1) - jsonArray.getJSONArray(i - 1).getInt(1)); json.put(6, list.getJSONArray(j).getDouble(2) - jsonArray.getJSONArray(i - 1).getInt(2)); } else { json.put(5, 0); json.put(6, 0); } } //json.put(7, (list.getJSONArray(j).getDouble(2)/list.getJSONArray(j).getDouble(1))/100);//? flag = true; break; } } //? if (!flag) { if (i == 0) { json.put(1, 0); json.put(2, 0); json.put(3, time); json.put(0, quoteData.getDouble("close")); } else { json.put(1, jsonArray.getJSONArray(i - 1).getDouble(1)); json.put(2, jsonArray.getJSONArray(i - 1).getDouble(2)); json.put(3, time); json.put(0, ((JSONArray) jsonArray.get(i - 1)).getDouble(0)); } json.put(4, 0); json.put(5, 0); json.put(6, 0); json.put(7, 0); } jsonArray.put(json); } } else if ("cf".equals(exchange)) { this.MINUTES = 270; Date dt1 = new Date(year, month, day, 9, 15); Date dt2 = new Date(year, month, day, 11, 30); Date dt3 = new Date(year, month, day, 13, 1); Date dt4 = new Date(year, month, day, 15, 15); long hopelen = 0; if (dt.getTime() < dt1.getTime()) { // 0 ? hopelen = 0; } if (dt.getTime() >= dt1.getTime() && dt.getTime() < dt2.getTime()) { hopelen = (dt.getTime() - dt1.getTime()) / 1000 / 60 + 1; } if (dt.getTime() >= dt2.getTime() && dt.getTime() < dt3.getTime()) { hopelen = 136; } if (dt.getTime() >= dt3.getTime() && dt.getTime() < dt4.getTime()) { hopelen = 136 + (dt.getTime() - dt3.getTime()) / 1000 / 60 + 1; } if (dt.getTime() >= dt4.getTime()) { hopelen = 271; } //?9.15 9.25 if (quoteData.getString("quotetime") == "null") { hopelen = 0; } String time = ""; for (int i = 0; i < hopelen; i++) { if (i < 136) { time = Utils.format(new Date(dt1.getTime() + 1000 * 60 * i)); } if (i >= 136 && i <= 271) { time = Utils.format(new Date(dt3.getTime() + 1000 * 60 * (i - 136))); } Boolean flag = false; JSONArray json = new JSONArray(); for (int j = 0; j < list.length(); j++) { if (list.getJSONArray(j).getString(3).equals(time)) { json.put(0, list.getJSONArray(j).getDouble(0)); json.put(1, list.getJSONArray(j).getDouble(1)); json.put(2, list.getJSONArray(j).getDouble(2)); json.put(3, list.getJSONArray(j).getString(3)); json.put(4, 1);//?? if (i == 0) { json.put(5, list.getJSONArray(j).getDouble(1));//?? json.put(6, list.getJSONArray(j).getDouble(2));//?? } else { if (jsonArray.getJSONArray(i - 1).getInt(4) == 1) { json.put(5, list.getJSONArray(j).getDouble(1) - jsonArray.getJSONArray(i - 1).getInt(1)); json.put(6, list.getJSONArray(j).getDouble(2) - jsonArray.getJSONArray(i - 1).getInt(2)); } else { json.put(5, 0); json.put(6, 0); } } //json.put(7, (list.getJSONArray(j).getDouble(2)/list.getJSONArray(j).getDouble(1))/100);//? flag = true; break; } } //? if (!flag) { if (i == 0) { json.put(1, 0); json.put(2, 0); json.put(3, time); json.put(0, quoteData.getDouble("jrkp")); } else { json.put(1, jsonArray.getJSONArray(i - 1).getDouble(1)); json.put(2, jsonArray.getJSONArray(i - 1).getDouble(2)); json.put(3, time); json.put(0, ((JSONArray) jsonArray.get(i - 1)).getDouble(0)); } json.put(4, 0); json.put(5, 0); json.put(6, 0); json.put(7, 0); } jsonArray.put(json); } } else if ("dc".equals(exchange) || "sf".equals(exchange) || "cz".equals(exchange)) { this.MINUTES = 225; Date dt1 = new Date(year, month, day, 9, 0); Date dt2 = new Date(year, month, day, 10, 15); Date dt3 = new Date(year, month, day, 10, 31); Date dt4 = new Date(year, month, day, 11, 30); Date dt5 = new Date(year, month, day, 13, 31); Date dt6 = new Date(year, month, day, 15, 0); long hopelen = 0; if (dt.getTime() < dt1.getTime()) { // 0 ? hopelen = 0; } if (dt.getTime() >= dt1.getTime() && dt.getTime() < dt2.getTime()) { hopelen = (dt.getTime() - dt1.getTime()) / 1000 / 60 + 1; } if (dt.getTime() >= dt2.getTime() && dt.getTime() < dt3.getTime()) { hopelen = 76; } if (dt.getTime() >= dt3.getTime() && dt.getTime() < dt4.getTime()) { hopelen = 76 + (dt.getTime() - dt3.getTime()) / 1000 / 60 + 1; } if (dt.getTime() >= dt4.getTime() && dt.getTime() < dt5.getTime()) { hopelen = 136; } if (dt.getTime() >= dt5.getTime() && dt.getTime() < dt6.getTime()) { hopelen = 136 + (dt.getTime() - dt5.getTime()) / 1000 / 60 + 1; } if (dt.getTime() >= dt6.getTime()) { hopelen = 226; } //?9.15 9.25 if (quoteData.getString("quotetime") == "null") { hopelen = 0; } String time = ""; for (int i = 0; i < hopelen; i++) { if (i < 76) { time = Utils.format(new Date(dt1.getTime() + 1000 * 60 * i)); } if (i >= 76 && i < 136) { time = Utils.format(new Date(dt3.getTime() + 1000 * 60 * (i - 76))); } if (i >= 136 && i <= 226) { time = Utils.format(new Date(dt5.getTime() + 1000 * 60 * (i - 136))); } Boolean flag = false; JSONArray json = new JSONArray(); for (int j = 0; j < list.length(); j++) { if (list.getJSONArray(j).getString(3).equals(time)) { json.put(0, list.getJSONArray(j).getDouble(0)); json.put(1, list.getJSONArray(j).getDouble(1)); json.put(2, list.getJSONArray(j).getDouble(2)); json.put(3, list.getJSONArray(j).getString(3)); json.put(4, 1);//?? if (i == 0) { json.put(5, list.getJSONArray(j).getDouble(1));//?? json.put(6, list.getJSONArray(j).getDouble(2));//?? } else { if (jsonArray.getJSONArray(i - 1).getInt(4) == 1) { json.put(5, list.getJSONArray(j).getDouble(1) - jsonArray.getJSONArray(i - 1).getInt(1)); json.put(6, list.getJSONArray(j).getDouble(2) - jsonArray.getJSONArray(i - 1).getInt(2)); } else { json.put(5, 0); json.put(6, 0); } } //json.put(7, (list.getJSONArray(j).getDouble(2)/list.getJSONArray(j).getDouble(1))/100);//? flag = true; break; } } //? if (!flag) { if (i == 0) { json.put(1, 0); json.put(2, 0); json.put(3, time); json.put(0, quoteData.getDouble("jrkp")); } else { json.put(1, jsonArray.getJSONArray(i - 1).getDouble(1)); json.put(2, jsonArray.getJSONArray(i - 1).getDouble(2)); json.put(3, time); json.put(0, ((JSONArray) jsonArray.get(i - 1)).getDouble(0)); } json.put(4, 0); json.put(5, 0); json.put(6, 0); json.put(7, 0); } jsonArray.put(json); } } else { Date dt1 = new Date(year, month, day, 9, 30); Date dt2 = new Date(year, month, day, 11, 30); Date dt3 = new Date(year, month, day, 13, 1); Date dt4 = new Date(year, month, day, 15, 0); long hopelen = 0; if (dt.getTime() < dt1.getTime()) { // 0 ? hopelen = 0; } if (dt.getTime() >= dt1.getTime() && dt.getTime() < dt2.getTime()) { hopelen = (dt.getTime() - dt1.getTime()) / 1000 / 60 + 1; } if (dt.getTime() >= dt2.getTime() && dt.getTime() < dt3.getTime()) { hopelen = 121; } if (dt.getTime() >= dt3.getTime() && dt.getTime() < dt4.getTime()) { hopelen = 121 + (dt.getTime() - dt3.getTime()) / 1000 / 60 + 1; } if (dt.getTime() >= dt4.getTime()) { hopelen = 241; } //?9.15 9.25 if (quoteData.getString("quotetime") == "null") { hopelen = 0; } String time = ""; for (int i = 0; i < hopelen; i++) { if (i < 121) { time = Utils.format(new Date(dt1.getTime() + 1000 * 60 * i)); } if (i >= 121 && i <= 241) { time = Utils.format(new Date(dt3.getTime() + 1000 * 60 * (i - 121))); } Boolean flag = false; JSONArray json = new JSONArray(); for (int j = 0; j < list.length(); j++) { if (list.getJSONArray(j).getString(3).equals(time)) { json.put(0, list.getJSONArray(j).getDouble(0)); json.put(1, list.getJSONArray(j).getDouble(1)); json.put(2, list.getJSONArray(j).getDouble(2)); json.put(3, list.getJSONArray(j).getString(3)); json.put(4, 1);//?? if (i == 0) { json.put(5, list.getJSONArray(j).getDouble(1));//?? json.put(6, list.getJSONArray(j).getDouble(2));//?? } else { if (jsonArray.getJSONArray(i - 1).getInt(4) == 1) { json.put(5, list.getJSONArray(j).getDouble(1) - jsonArray.getJSONArray(i - 1).getInt(1)); json.put(6, list.getJSONArray(j).getDouble(2) - jsonArray.getJSONArray(i - 1).getInt(2)); } else { json.put(5, 0); json.put(6, 0); } } //json.put(7, (list.getJSONArray(j).getDouble(2)/list.getJSONArray(j).getDouble(1))/100);//? flag = true; break; } } //? if (!flag) { if (i == 0) { json.put(1, 0); json.put(2, 0); json.put(3, time); json.put(0, quoteData.getDouble("close")); } else { json.put(1, jsonArray.getJSONArray(i - 1).getDouble(1)); json.put(2, jsonArray.getJSONArray(i - 1).getDouble(2)); json.put(3, time); json.put(0, ((JSONArray) jsonArray.get(i - 1)).getDouble(0)); } json.put(4, 0); json.put(5, 0); json.put(6, 0); json.put(7, 0); } jsonArray.put(json); } } //Log.i("#########getSecurityType##########", NameRule.getSecurityType(exchange, stockcode)+">>>>>>>>>>>>>>"); // if(NameRule.getSecurityType(exchange, stockcode)==15 // || NameRule.getSecurityType(exchange, stockcode)==5 // || NameRule.getSecurityType(exchange, stockcode)==35){ // quoteArray = null; // return; // }else{ // quoteArray = jsonArray; // } quoteArray = jsonArray; actualDataLen = quoteArray.length(); if (!isTrackStatus) isTrackNumber = actualDataLen - 1;//?? highvolume = TickUtil.gethighVolume(quoteArray); highamount = TickUtil.gethighAmount(quoteArray); high = Math.max(TickUtil.gethighPrice(quoteArray, quoteArray.length()), close); low = Math.min(TickUtil.getlowPrice(quoteArray, quoteArray.length()), close); if ("sz399001".equals(exchange + stockcode) || "sh000001".equals(exchange + stockcode)) { //?????? int len = quoteData.getJSONArray("data2").length() - 1; high = Math.max(high, TickUtil.gethighPrice(quoteData.getJSONArray("data2"), len)); low = Math.min(low, TickUtil.getlowPrice(quoteData.getJSONArray("data2"), len)); } }