Java Code Examples for org.json.JSONArray#getDouble()

The following examples show how to use org.json.JSONArray#getDouble() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ShowAdvancedPolylineStyles.java    From osmdroid with Apache License 2.0 6 votes vote down vote up
private ArrayList<GeoPoint> getPoints(String identifier) {
    ArrayList<GeoPoint> points = new ArrayList<>();
    try {
        JSONObject example = (JSONObject) mData.get(identifier);
        JSONArray array = example.getJSONArray("geopoints");

        for (int i = 0; i < array.length(); i += 2) {
            final double lat = array.getDouble(i);
            final double lon = array.getDouble(i + 1);
            points.add(new GeoPoint(lat, lon));
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    return points;
}
 
Example 2
Source File: JavaFXSplitPaneElementTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Test
public void select() {
    SplitPane splitPaneNode = (SplitPane) getPrimaryStage().getScene().getRoot().lookup(".split-pane");
    JSONArray initialValue = new JSONArray(splitPaneNode.getDividerPositions());
    Platform.runLater(() -> {
        splitPane.marathon_select("[0.6]");
    });
    new Wait("Waiting for split pane to set divider location") {
        @Override
        public boolean until() {
            return initialValue.getDouble(0) != new JSONArray(splitPaneNode.getDividerPositions()).getDouble(0);
        }
    };
    JSONArray pa = new JSONArray(splitPaneNode.getDividerPositions());
    AssertJUnit.assertEquals(0.6, pa.getDouble(0), 0.2);
}
 
Example 3
Source File: JavaFXSplitPaneElementTest.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Test
public void select2() {
    SplitPane splitPaneNode = (SplitPane) getPrimaryStage().getScene().getRoot().lookup(".split-pane");
    JSONArray initialValue = new JSONArray(splitPaneNode.getDividerPositions());
    Platform.runLater(() -> {
        splitPane.marathon_select("[0.30158730158730157,0.8]");
    });
    new Wait("Waiting for split pane to set divider location") {
        @Override
        public boolean until() {
            return initialValue.getDouble(1) != new JSONArray(splitPaneNode.getDividerPositions()).getDouble(1);
        }
    };
    JSONArray pa = new JSONArray(splitPaneNode.getDividerPositions());
    AssertJUnit.assertEquals(0.8, pa.getDouble(1), 0.1);
}
 
Example 4
Source File: JsonUtils.java    From sdl_java_suite with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static List<Double> readDoubleListFromJsonObject(JSONObject json, String key){
	JSONArray jsonArray = readJsonArrayFromJsonObject(json, key);
	
	if(jsonArray != null){
		int len = jsonArray.length();
		List<Double> result = new ArrayList<Double>(len);
		for(int i=0; i<len; i++){
			try {
				Double str = jsonArray.getDouble(i);
				result.add(str);
			} catch (JSONException e) {}
		}
		return result;
	}
	
	return null;
}
 
Example 5
Source File: JSONUtil.java    From browser with GNU General Public License v2.0 6 votes vote down vote up
public static double[] getArrayDouble(JSONObject docObj, String name) {
	double[] list = null;
	if (docObj.has(name)) {
		JSONArray json;
		try {
			json = docObj.getJSONArray(name);
			int lenFeatures = json.length();
			list = new double[lenFeatures];
			for (int j = 0; j < lenFeatures; j++) {
				double f = json.getDouble(j);
				list[j] = f;
			}
		} catch (JSONException e) {
			e.printStackTrace();
		}

	}
	return list;

}
 
Example 6
Source File: FilterFactory.java    From Fatigue-Detection with MIT License 6 votes vote down vote up
public static ChangeFaceInfo parseChangeFaceJson(String paramString)
        throws JSONException {
    ChangeFaceInfo localChangeFaceInfo = new ChangeFaceInfo();
    JSONObject localJSONObject = new JSONObject(paramString);

    JSONArray localJSONArray1 = localJSONObject.getJSONArray("params");
    localChangeFaceInfo.bO = new float[localJSONArray1.length()];
    for (int i = 0; i < localJSONArray1.length(); i++) {
        localChangeFaceInfo.bO[i] = ((float) localJSONArray1.getDouble(i));
    }
    JSONArray localJSONArray2 = localJSONObject.getJSONArray("reslist");
    localChangeFaceInfo.bR = new String[localJSONArray2.length()];
    for (int j = 0; j < localJSONArray2.length(); j++) {
        localChangeFaceInfo.bR[j] = localJSONArray2.getString(j);
    }
    localChangeFaceInfo.bP = localJSONObject.getString("tips");
    localChangeFaceInfo.bQ = localJSONObject.getInt("soundPlayMode");
    localChangeFaceInfo.bS = localJSONObject.optString("audio");
    localChangeFaceInfo.bT = (localJSONObject.optInt("disableEnvFilter", 0) == 1);

    return localChangeFaceInfo;
}
 
Example 7
Source File: FPPage.java    From OpenMapKitAndroid with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
private void buildGeometryAndPathOverlay() {
    try {
        pathOverlay = new PathOverlay();
        Paint paint = pathOverlay.getPaint();
        paint.setColor(Color.BLACK);
        paint.setStrokeWidth(4.0f);
        JSONArray coords = feature.getJSONObject("geometry").getJSONArray("coordinates").getJSONArray(0);
        int len = coords.length();
        Coordinate[] coordinates = new Coordinate[len];
        for (int i = 0; i < len; ++i) {
            JSONArray coord = coords.getJSONArray(i);
            double lng = coord.getDouble(0);
            double lat = coord.getDouble(1);
            coordinates[i] = new Coordinate(lng, lat);
            pathOverlay.addPoint(lat, lng);
        }
        geom = FPAtlas.GEOMETRY_FACTORY.createPolygon(coordinates);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}
 
Example 8
Source File: HistoricalData.java    From javakiteconnect with MIT License 6 votes vote down vote up
public void parseResponse(JSONObject response) throws JSONException {
    JSONObject data = response.getJSONObject("data");
    JSONArray candleArray = data.getJSONArray("candles");
    for(int i = 0; i < candleArray.length(); i++){
        JSONArray itemArray = candleArray.getJSONArray(i);
        HistoricalData historicalData = new HistoricalData();
        historicalData.timeStamp = itemArray.getString(0);
        historicalData.open = itemArray.getDouble(1);
        historicalData.high = itemArray.getDouble(2);
        historicalData.low = itemArray.getDouble(3);
        historicalData.close = itemArray.getDouble(4);
        historicalData.volume = itemArray.getLong(5);
        if(itemArray.length() > 6)
        historicalData.oi = itemArray.getLong(6);
        dataArrayList.add(historicalData);
    }
}
 
Example 9
Source File: FilterFactory.java    From Fatigue-Detection with MIT License 5 votes vote down vote up
static GroupData a(String paramString, JSONObject paramJSONObject)
        throws JSONException, IOException {
    GroupData locala = new GroupData();
    locala.name = paramJSONObject.getString("foldername");
    locala.cN = paramJSONObject.getInt("maxcount");
    locala.ee = paramJSONObject.getInt("resloadtype");
    locala.bS = paramJSONObject.getString("audio");
    locala.bQ = paramJSONObject.getInt("soundPlayMode");
    locala.di = paramJSONObject.getInt("triggerType");

    locala.cv = new ArrayList();
    JSONArray localJSONArray1 = paramJSONObject.getJSONArray("pointindexarray");
    for (int i = 0; i < localJSONArray1.length(); i++) {
        JSONArray localJSONArray3 = localJSONArray1.getJSONArray(i);
        for (int k = 0; k < localJSONArray3.length(); k++) {
            GroupData.b locala1 = new GroupData.b();
            locala1.cx = i;
            locala1.cy = localJSONArray3.getInt(k);
            locala.cv.add(locala1);
        }
    }
    locala.bO = new float[8];
    JSONArray localJSONArray2 = paramJSONObject.getJSONArray("timeparam");
    for (int j = 0; j < 8; j++) {
        locala.bO[j] = ((float) localJSONArray2.getDouble(j));
    }
    JSONArray localJSONArray4 = paramJSONObject.getJSONArray("reslist");
    locala.ed = new ArrayList();
    for (int k = 0; k < localJSONArray4.length(); k++) {
        locala.ed.add(localJSONArray4.getString(k));
    }
    File localFile = new File(paramString + "/" + locala.name, "glsl");
    locala.bN = IOUtils.convertStreamToString(new FileInputStream(localFile));
    return locala;
}
 
Example 10
Source File: ConvertUtils.java    From cidrawing with Apache License 2.0 5 votes vote down vote up
public static PointF pointFromJson(JSONArray array) throws JSONException {
    if (array == null) {
        return null;
    }
    PointF point = new PointF();
    point.x = (float) array.getDouble(0);
    point.y = (float) array.getDouble(1);
    return point;
}
 
Example 11
Source File: GeoJsonParser.java    From android-maps-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Parses an array containing a coordinate into a LatLngAlt object
 *
 * @param coordinates array containing the GeoJSON coordinate
 * @return LatLngAlt object
 * @throws JSONException if coordinate cannot be parsed
 */
private static LatLngAlt parseCoordinate(JSONArray coordinates) throws JSONException {
    // GeoJSON stores coordinates as Lng, Lat so we need to reverse
    LatLng latLng = new LatLng(coordinates.getDouble(1), coordinates.getDouble(0));
    Double altitude = (coordinates.length() < 3) ? null : coordinates.getDouble(2);

    return new LatLngAlt(latLng, altitude);
}
 
Example 12
Source File: QSJSONUtil.java    From qingstor-sdk-java with Apache License 2.0 5 votes vote down vote up
public static Double toDouble(JSONArray labelDatas, int i) {
    if (labelDatas == null || labelDatas.length() <= i) return 0.0;
    double rst = 0;
    try {
        rst = labelDatas.getDouble(i);
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return rst;
}
 
Example 13
Source File: PanakoWebserviceClient.java    From Panako with GNU Affero General Public License v3.0 5 votes vote down vote up
public static List<Double> beatListFromResponse(String response){
    List<Double> beatList = new ArrayList<Double>();
    try{
        JSONObject metadata = new JSONObject(response);
        JSONArray beats = metadata.getJSONObject("rhythm").getJSONArray("beats_position");
        for(int i = 0 ; i < beats.length();i++) {
            double tapAtTime = (beats.getDouble(i));
            beatList.add(tapAtTime);
        }
    } catch (JSONException e) {
        e.printStackTrace();
    }
    return beatList;
}
 
Example 14
Source File: SinglePeptideDisplay.java    From PDV with GNU General Public License v3.0 5 votes vote down vote up
private void generateSpectrum(JSONArray mzs, JSONArray intensities, Precursor precursor){

        HashMap<Double, Peak> peakMap = new HashMap<>();
        for(int i = 0; i<mzs.length(); i++){
            Peak peak = new Peak(mzs.getDouble(i), intensities.getDouble(i));
            peakMap.put(mzs.getDouble(i), peak);
        }

        currentSpectrum = new MSnSpectrum(2, precursor, "1", peakMap, "test");

        validateInput();
    }
 
Example 15
Source File: MainActivity.java    From Acastus with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Fill lists.
 *
 * @param object the object
 * @throws JSONException the json exception
 */
void fillLists(JSONObject object) throws JSONException {
    JSONArray array = object.getJSONArray("features");
    lookupList.clear();
    labels.clear();
    double lat, lon;
    for (int i = 0; i < array.length(); i++) {
        JSONObject initialArray = array.getJSONObject(i);
        JSONObject geometry = initialArray.getJSONObject("geometry");
        JSONObject properties = initialArray.getJSONObject("properties");
        JSONArray coordinates = geometry.getJSONArray("coordinates");
        lat = coordinates.getDouble(1);
        lon = coordinates.getDouble(0);
        String name = properties.getString("label");
        ResultNode tempNode = new ResultNode();
        tempNode.lat = lat;
        tempNode.lon = lon;
        tempNode.name = name;
        if (useLocation) {
            Boolean kilometers = prefs.getBoolean("unit_length", false);
            Double distance = geoLocation.distance(curLat, lat, curLon, lon, kilometers);
            if (kilometers){
                labels.add(name + " : " + distance + " km");
            }else{
                labels.add(name + " : " + distance + " mi");
            }
        } else {
            labels.add(name);
        }
        lookupList.add(tempNode);
    }
}
 
Example 16
Source File: ParseTypes.java    From cordova-plugin-app-launcher with MIT License 5 votes vote down vote up
public static double[] toDoubleArray(JSONArray arr) throws JSONException {
	int jsize = arr.length();
	double[] exVal = new double[jsize];
	for(int j=0; j < jsize; j++) {
		exVal[j] = arr.getDouble(j);
	}
	return exVal;
}
 
Example 17
Source File: FilterFactory.java    From Fatigue-Detection with MIT License 4 votes vote down vote up
public static MakeupData parseMakeUpInfo(String paramString, JSONObject paramJSONObject)
        throws IOException, JSONException {
    MakeupData locala = new MakeupData();
    locala.ep = paramJSONObject.getInt("resloadtype");
    locala.name = paramJSONObject.getString("foldername");
    locala.cN = paramJSONObject.getInt("maxcount");
    JSONArray localJSONArray1 = paramJSONObject.getJSONArray("triangles");
    locala.cN = Math.min(localJSONArray1.length(), locala.cN);

    locala.eo = new ArrayList();
    for (int i = 0; i < locala.cN; i++) {
        MakeupData.a locala1 = new MakeupData.a();
        JSONObject localJSONObject = localJSONArray1.getJSONObject(i);

        locala1.eq = localJSONObject.getString("res");
        JSONArray localJSONArray2 = localJSONObject.getJSONArray("vertexIndexes");
        locala1.er = new int[localJSONArray2.length()];
        for (int j = 0; j < localJSONArray2.length(); j++) {
            locala1.er[j] = localJSONArray2.getInt(j);
        }
        JSONArray localJSONArray3 = localJSONObject.optJSONArray("facePointOffset");
        if (null != localJSONArray3) {
            if (localJSONArray3.length() % 5 != 0) {
                throw new JSONException("facePointOffset is not multiple of 5");
            }
            locala1.es = new MakeupData.b[localJSONArray3.length() / 5];
            for (int k = 0; k < locala1.es.length; k++) {
                MakeupData.b localb = new MakeupData.b();
                localb.ew = localJSONArray3.getInt(5 * k);
                localb.ex = localJSONArray3.getInt(5 * k + 1);
                localb.ey = ((float) localJSONArray3.getDouble(5 * k + 2));
                localb.ez = localJSONArray3.getInt(5 * k + 3);
                localb.eA = ((float) localJSONArray3.getDouble(5 * k + 4));
                locala1.es[k] = localb;
            }
        } else {
            locala1.es = new MakeupData.b[0];
        }
        JSONArray localJSONArray4 = localJSONObject.getJSONArray("resFacePoints");
        if (localJSONArray4.length() != 212) {
            throw new JSONException("resFacePoints size is error");
        }
        locala1.et = new PointF[106];
        for (int m = 0; m < 106; m++) {
            locala1.et[m] = new PointF((float) localJSONArray4.getDouble(2 * m), (float) localJSONArray4.getDouble(2 * m + 1));
        }
        locala1.ev = (localJSONObject.optInt("inheritoffset") == 1);
        locala.eo.add(locala1);
    }
    return locala;
}
 
Example 18
Source File: FilterFactory.java    From Fatigue-Detection with MIT License 4 votes vote down vote up
static MultiTriangleInfo g(String paramString)
        throws JSONException {
    MultiTriangleInfo localMultiTriangleInfo = new MultiTriangleInfo();
    JSONObject localJSONObject1 = new JSONObject(paramString);
    localMultiTriangleInfo.eI = new ArrayList();
    localMultiTriangleInfo.bP = localJSONObject1.getString("tips");

    JSONArray localJSONArray1 = localJSONObject1.getJSONArray("itemlist");
    for (int i = 0; i < localJSONArray1.length(); i++) {
        MultiTriangleInfo.a locala = new MultiTriangleInfo.a();
        JSONObject localJSONObject2 = localJSONArray1.getJSONObject(i);

        locala.eq = localJSONObject2.getString("resname");
        JSONArray localJSONArray2 = localJSONObject2.getJSONArray("vertexidx");
        locala.eJ = new int[localJSONArray2.length()];
        for (int j = 0; j < localJSONArray2.length(); j++) {
            locala.eJ[j] = localJSONArray2.getInt(j);
        }
        JSONArray localJSONArray3 = localJSONObject2.getJSONArray("resFacePointsKey");
        locala.eN = new int[localJSONArray3.length()];
        for (int k = 0; k < localJSONArray3.length(); k++) {
            locala.eN[k] = localJSONArray3.getInt(k);
        }
        JSONArray localJSONArray4 = localJSONObject2.getJSONArray("resFacePointsValue");
        locala.eO = new PointF[localJSONArray4.length() / 2];
        for (int m = 0; m < locala.eO.length; m++) {
            locala.eO[m] = new PointF();
            locala.eO[m].x = ((float) localJSONArray4.getDouble(2 * m));
            locala.eO[m].y = ((float) localJSONArray4.getDouble(2 * m + 1));
        }
        JSONArray localJSONArray5 = localJSONObject2.getJSONArray("scaleIdx");
        locala.eK = new int[2];
        locala.eK[0] = localJSONArray5.getInt(0);
        locala.eK[1] = localJSONArray5.getInt(1);

        JSONArray localJSONArray6 = localJSONObject2.getJSONArray("baselineIdx");
        locala.eL = new int[localJSONArray6.length()];
        for (int n = 0; n < localJSONArray6.length(); n++) {
            locala.eL[n] = localJSONArray6.getInt(n);
        }
        JSONArray localJSONArray7 = localJSONObject2.getJSONArray("fakePosScaleRatio");
        locala.eM = new PointF[localJSONArray7.length() / 2];
        for (int i1 = 0; i1 < locala.eM.length; i1++) {
            locala.eM[i1] = new PointF();
            locala.eM[i1].x = ((float) localJSONArray7.getDouble(2 * i1));
            locala.eM[i1].y = ((float) localJSONArray7.getDouble(2 * i1 + 1));
        }
        localMultiTriangleInfo.eI.add(locala);
    }
    return localMultiTriangleInfo;
}
 
Example 19
Source File: JsCallJava.java    From AgentWeb with Apache License 2.0 4 votes vote down vote up
public String call(WebView webView, JSONObject jsonObject) {
    long time = 0;
    if (LogUtils.isDebug()) {
        time = android.os.SystemClock.uptimeMillis();
    }
    if (jsonObject != null) {
        try {
            String methodName = jsonObject.getString(KEY_METHOD);
            JSONArray argsTypes = jsonObject.getJSONArray(KEY_TYPES);
            JSONArray argsVals = jsonObject.getJSONArray(KEY_ARGS);
            String sign = methodName;
            int len = argsTypes.length();
            Object[] values = new Object[len];
            int numIndex = 0;
            String currType;

            for (int k = 0; k < len; k++) {
                currType = argsTypes.optString(k);
                if ("string".equals(currType)) {
                    sign += "_S";
                    values[k] = argsVals.isNull(k) ? null : argsVals.getString(k);
                } else if ("number".equals(currType)) {
                    sign += "_N";
                    numIndex = numIndex * 10 + k + 1;
                } else if ("boolean".equals(currType)) {
                    sign += "_B";
                    values[k] = argsVals.getBoolean(k);
                } else if ("object".equals(currType)) {
                    sign += "_O";
                    values[k] = argsVals.isNull(k) ? null : argsVals.getJSONObject(k);
                } else if ("function".equals(currType)) {
                    sign += "_F";
                    values[k] = new JsCallback(webView, mInterfacedName, argsVals.getInt(k));
                } else {
                    sign += "_P";
                }
            }

            Method currMethod = mMethodsMap.get(sign);

            // 方法匹配失败
            if (currMethod == null) {
                return getReturn(jsonObject, 500, "not found method(" + sign + ") with valid parameters", time);
            }
            // 数字类型细分匹配
            if (numIndex > 0) {
                Class[] methodTypes = currMethod.getParameterTypes();
                int currIndex;
                Class currCls;
                while (numIndex > 0) {
                    currIndex = numIndex - numIndex / 10 * 10 - 1;
                    currCls = methodTypes[currIndex];
                    if (currCls == int.class) {
                        values[currIndex] = argsVals.getInt(currIndex);
                    } else if (currCls == long.class) {
                        //WARN: argsJson.getLong(k + defValue) will return a bigger incorrect number
                        values[currIndex] = Long.parseLong(argsVals.getString(currIndex));
                    } else {
                        values[currIndex] = argsVals.getDouble(currIndex);
                    }
                    numIndex /= 10;
                }
            }

            return getReturn(jsonObject, 200, currMethod.invoke(mInterfaceObj, values), time);
        } catch (Exception e) {
            LogUtils.safeCheckCrash(TAG, "call", e);
            //优先返回详细的错误信息
            if (e.getCause() != null) {
                return getReturn(jsonObject, 500, "method execute result:" + e.getCause().getMessage(), time);
            }
            return getReturn(jsonObject, 500, "method execute result:" + e.getMessage(), time);
        }
    } else {
        return getReturn(jsonObject, 500, "call data empty", time);
    }
}
 
Example 20
Source File: GeoJsonParser.java    From android-maps-utils with Apache License 2.0 3 votes vote down vote up
/**
 * Parses a bounding box given as a JSONArray of 4 elements in the order of lowest values for
 * all axes followed by highest values. Axes order of a bounding box follows the axes order of
 * geometries.
 *
 * @param coordinates array of 4 coordinates
 * @return LatLngBounds containing the coordinates of the bounding box
 * @throws JSONException if the bounding box could not be parsed
 */
private static LatLngBounds parseBoundingBox(JSONArray coordinates) throws JSONException {
    // Lowest values for all axes
    LatLng southWestCorner = new LatLng(coordinates.getDouble(1), coordinates.getDouble(0));
    // Highest value for all axes
    LatLng northEastCorner = new LatLng(coordinates.getDouble(3), coordinates.getDouble(2));
    return new LatLngBounds(southWestCorner, northEastCorner);
}