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

The following examples show how to use org.json.JSONArray#getJSONArray() . 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: FederationDefinition.java    From Knowage-Server with GNU Affero General Public License v3.0 6 votes vote down vote up
/**
 * Flats the relationships and return the single relations between couple tables
 *
 * @return
 * @throws JSONException
 */
@JsonIgnore
public JSONArray getFlatReslationsShips() throws JSONException {

	JSONArray flatJSONArray = new JSONArray();
	if (getRelationships() != null && getRelationships().length() > 0) {
		JSONArray array = new JSONArray(getRelationships());
		if (array != null && array.length() > 0) {
			for (int i = 0; i < array.length(); i++) {
				JSONArray temp = array.getJSONArray(i);
				for (int j = 0; j < temp.length(); j++) {
					flatJSONArray.put(temp.get(j));
				}
			}
		}
	}

	return flatJSONArray;
}
 
Example 2
Source File: GameRound.java    From PretendYoureXyzzyAndroid with GNU General Public License v3.0 6 votes vote down vote up
public GameRound(JSONObject obj) throws JSONException {
    gameId = obj.getString("GameId");
    timestamp = obj.getLong("Timestamp");
    blackCard = new RoundCard(obj.getJSONObject("BlackCard"));

    JSONArray winningPlay = obj.getJSONArray("WinningPlay");
    winningCard = new ArrayList<>(winningPlay.length());
    for (int i = 0; i < winningPlay.length(); i++)
        winningCard.add(new RoundCard(winningPlay.getJSONObject(i)));

    JSONArray otherPlays = obj.getJSONArray("OtherPlays");
    otherCards = new ArrayList<>(otherPlays.length());
    for (int i = 0; i < otherPlays.length(); i++) {
        JSONArray sub = otherPlays.getJSONArray(i);
        List<RoundCard> subCards = new ArrayList<>(sub.length());
        otherCards.add(subCards);
        for (int j = 0; j < sub.length(); j++)
            subCards.add(new RoundCard(sub.getJSONObject(j)));
    }
}
 
Example 3
Source File: GoogleTranslator.java    From SnowGraph with Apache License 2.0 5 votes vote down vote up
@Override
protected String parseString(String jsonString){
	JSONArray jsonArray = new JSONArray(jsonString);
	JSONArray segments = jsonArray.getJSONArray(0);
	StringBuilder result = new StringBuilder();
	
	for(int i=0; i<segments.length(); i++){
		result.append(segments.getJSONArray(i).getString(0));
	}
	
	return new String(result);
}
 
Example 4
Source File: QSJSONUtil.java    From qingstor-sdk-java with Apache License 2.0 5 votes vote down vote up
public static JSONArray toJSONArray(JSONArray obj, int i) {
    JSONArray res = null;
    if (obj.length() > i) {
        try {
            res = obj.getJSONArray(i);
        } catch (JSONException e) {
            e.printStackTrace();
        }
    }
    return res;
}
 
Example 5
Source File: Vibration.java    From reacteu-app with MIT License 5 votes vote down vote up
/**
 * Executes the request and returns PluginResult.
 *
 * @param action            The action to execute.
 * @param args              JSONArray of arguments for the plugin.
 * @param callbackContext   The callback context used when calling back into JavaScript.
 * @return                  True when the action was valid, false otherwise.
 */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if (action.equals("vibrate")) {
        this.vibrate(args.getLong(0));
    }
    else if (action.equals("vibrateWithPattern")) {
        JSONArray pattern = args.getJSONArray(0);
        int repeat = args.getInt(1);
        //add a 0 at the beginning of pattern to align with w3c
        long[] patternArray = new long[pattern.length()+1];
        patternArray[0] = 0;
        for (int i = 0; i < pattern.length(); i++) {
            patternArray[i+1] = pattern.getLong(i);
        }
        this.vibrateWithPattern(patternArray, repeat);
    }
    else if (action.equals("cancelVibration")) {
        this.cancelVibration();
    }
    else {
        return false;
    }

    // Only alert and confirm are async.
    callbackContext.success();

    return true;
}
 
Example 6
Source File: GeoPolygon.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public void setCoordinatesFromJSON(JSONArray coordinates)
        throws JSONException
{
    JSONArray ringCoordinates = coordinates.getJSONArray(0);

    if (ringCoordinates.length() < 4) {
        throw new JSONException(
                "For type \"Polygon\", the \"coordinates\" member must be an array of LinearRing coordinate arrays. A LinearRing must be with 4 or more positions.");
    }

    mOuterRing.setCoordinatesFromJSON(ringCoordinates);

    if (!getOuterRing().isClosed()) {
        throw new JSONException(
                "For type \"Polygon\", the \"coordinates\" member must be an array of LinearRing coordinate arrays. The first and last positions of LinearRing must be equivalent (they represent equivalent points).");
    }

    GeoLinearRing innerRing;

    for (int i = 1; i < coordinates.length(); i++) {
        ringCoordinates = coordinates.getJSONArray(i);

        if (ringCoordinates.length() < 4) {
            throw new JSONException(
                    "For type \"Polygon\", the \"coordinates\" member must be an array of LinearRing coordinate arrays. A LinearRing must be with 4 or more positions.");
        }

        innerRing = new GeoLinearRing();
        innerRing.setCoordinatesFromJSON(ringCoordinates);

        if (!innerRing.isClosed()) {
            throw new JSONException(
                    "For type \"Polygon\", the \"coordinates\" member must be an array of LinearRing coordinate arrays. The first and last positions of LinearRing must be equivalent (they represent equivalent points).");
        }

        addInnerRing(innerRing);
    }
}
 
Example 7
Source File: FilterFactory.java    From Fatigue-Detection with MIT License 5 votes vote down vote up
public static DecorateFaceBean parseDecorateFaceJson(String paramString)
        throws JSONException {
    DecorateFaceBean locala = new DecorateFaceBean();
    JSONObject localJSONObject = new JSONObject(paramString);

    locala.bP = localJSONObject.getString("tips");
    locala.cw = localJSONObject.getInt("count");
    locala.cv = new ArrayList();

    JSONArray localJSONArray1 = localJSONObject.getJSONArray("reslist");
    locala.bR = new String[localJSONArray1.length()];
    for (int i = 0; i < localJSONArray1.length(); i++) {
        locala.bR[i] = localJSONArray1.getString(i);
    }
    JSONArray localJSONArray2 = localJSONObject.getJSONArray("pointIndexArray");
    for (int j = 0; j < localJSONArray2.length(); j++) {
        if (j < locala.cw) {
            JSONArray localJSONArray3 = localJSONArray2.getJSONArray(j);
            for (int k = 0; k < localJSONArray3.length(); k++) {
                DecorateFaceBean.a locala1 = new DecorateFaceBean.a();
                locala1.cx = j;
                locala1.cy = localJSONArray3.getInt(k);
                locala.cv.add(locala1);
            }
        }
    }
    return locala;
}
 
Example 8
Source File: FilterFactory.java    From Fatigue-Detection with MIT License 5 votes vote down vote up
public static SwitchFaceInfo parseSwitchFaceJson(String paramString)
        throws JSONException {
    SwitchFaceInfo localSwitchFaceInfo = new SwitchFaceInfo();
    JSONObject localJSONObject = new JSONObject(paramString);

    localSwitchFaceInfo.bP = localJSONObject.getString("tips");
    localSwitchFaceInfo.bQ = localJSONObject.optInt("soundPlayMode");
    localSwitchFaceInfo.bS = localJSONObject.optString("audio");
    localSwitchFaceInfo.cw = localJSONObject.getInt("count");
    localSwitchFaceInfo.cv = new ArrayList();

    JSONArray localJSONArray1 = localJSONObject.getJSONArray("reslist");
    localSwitchFaceInfo.bR = new String[localJSONArray1.length()];
    for (int i = 0; i < localJSONArray1.length(); i++) {
        localSwitchFaceInfo.bR[i] = localJSONArray1.getString(i);
    }
    JSONArray localJSONArray2 = localJSONObject.getJSONArray("pointIndexArray");
    for (int j = 0; j < localJSONArray2.length(); j++) {
        if (j < localSwitchFaceInfo.cw) {
            JSONArray localJSONArray3 = localJSONArray2.getJSONArray(j);
            for (int k = 0; k < localJSONArray3.length(); k++) {
                SwitchFaceInfo.a locala = new SwitchFaceInfo.a();
                locala.cx = j;
                locala.cy = localJSONArray3.getInt(k);
                localSwitchFaceInfo.cv.add(locala);
            }
        }
    }
    return localSwitchFaceInfo;
}
 
Example 9
Source File: SuggestionProvider.java    From SimplicityBrowser with MIT License 5 votes vote down vote up
private void parseResults(@NonNull String content,
                          @NonNull ResultCallback callback) throws Exception {
    JSONArray respArray = new JSONArray(content);
    JSONArray jsonArray = respArray.getJSONArray(1);
    for (int n = 0, size = jsonArray.length(); n < size; n++) {
        String suggestion = jsonArray.getString(n);
        if (!callback.addResult(suggestion)) {
            break;
        }
    }
}
 
Example 10
Source File: AssetRequest.java    From mdw with Apache License 2.0 5 votes vote down vote up
public AssetRequest(String asset, HttpMethod method, String path, JSONArray parameters) {
    this.asset = asset;
    this.method = method;
    this.path = path;
    if (parameters != null) {
        for (int i = 0; i < parameters.length(); i++) {
            JSONArray param = parameters.getJSONArray(i);
            addParameter(new Parameter(param));
        }
    }
}
 
Example 11
Source File: ObjectMapNamingStrategy.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
private List<List<String>> toList(JSONArray a) {
    List<List<String>> collection = new ArrayList<>();
    for (int i = 0; i < a.length(); i++) {
        JSONArray b = a.getJSONArray(i);
        List<String> c2 = new ArrayList<>();
        collection.add(c2);
        for (int j = 0; j < b.length(); j++) {
            String s = b.getString(j);
            c2.add(s);
        }
    }
    return collection;
}
 
Example 12
Source File: Vibration.java    From jpHolo with MIT License 5 votes vote down vote up
/**
 * Executes the request and returns PluginResult.
 *
 * @param action            The action to execute.
 * @param args              JSONArray of arguments for the plugin.
 * @param callbackContext   The callback context used when calling back into JavaScript.
 * @return                  True when the action was valid, false otherwise.
 */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if (action.equals("vibrate")) {
        this.vibrate(args.getLong(0));
    }
    else if (action.equals("vibrateWithPattern")) {
        JSONArray pattern = args.getJSONArray(0);
        int repeat = args.getInt(1);
        //add a 0 at the beginning of pattern to align with w3c
        long[] patternArray = new long[pattern.length()+1];
        patternArray[0] = 0;
        for (int i = 0; i < pattern.length(); i++) {
            patternArray[i+1] = pattern.getLong(i);
        }
        this.vibrateWithPattern(patternArray, repeat);
    }
    else if (action.equals("cancelVibration")) {
        this.cancelVibration();
    }
    else {
        return false;
    }

    // Only alert and confirm are async.
    callbackContext.success();

    return true;
}
 
Example 13
Source File: WebPlayerView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
protected String doInBackground(Void... voids) {
    String playerCode = downloadUrlContent(this, String.format(Locale.US, "http://www.aparat.com/video/video/embed/vt/frame/showvideo/yes/videohash/%s", videoId));
    if (isCancelled()) {
        return null;
    }
    try {
        Matcher filelist = aparatFileListPattern.matcher(playerCode);
        if (filelist.find()) {
            String jsonCode = filelist.group(1);
            JSONArray json = new JSONArray(jsonCode);
            for (int a = 0; a < json.length(); a++) {
                JSONArray array = json.getJSONArray(a);
                if (array.length() == 0) {
                    continue;
                }
                JSONObject object = array.getJSONObject(0);
                if (!object.has("file")) {
                    continue;
                }
                results[0] = object.getString("file");
                results[1] = "other";
            }
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
    return isCancelled() ? null : results[0];
}
 
Example 14
Source File: Vibration.java    From showCaseCordova with Apache License 2.0 5 votes vote down vote up
/**
 * Executes the request and returns PluginResult.
 *
 * @param action            The action to execute.
 * @param args              JSONArray of arguments for the plugin.
 * @param callbackContext   The callback context used when calling back into JavaScript.
 * @return                  True when the action was valid, false otherwise.
 */
public boolean execute(String action, JSONArray args, CallbackContext callbackContext) throws JSONException {
    if (action.equals("vibrate")) {
        this.vibrate(args.getLong(0));
    }
    else if (action.equals("vibrateWithPattern")) {
        JSONArray pattern = args.getJSONArray(0);
        int repeat = args.getInt(1);
        //add a 0 at the beginning of pattern to align with w3c
        long[] patternArray = new long[pattern.length()+1];
        patternArray[0] = 0;
        for (int i = 0; i < pattern.length(); i++) {
            patternArray[i+1] = pattern.getLong(i);
        }
        this.vibrateWithPattern(patternArray, repeat);
    }
    else if (action.equals("cancelVibration")) {
        this.cancelVibration();
    }
    else {
        return false;
    }

    // Only alert and confirm are async.
    callbackContext.success();

    return true;
}
 
Example 15
Source File: PathSet.java    From ripple-lib-java with ISC License 5 votes vote down vote up
@Override
public PathSet fromJSONArray(JSONArray array) {
    PathSet paths = new PathSet();

    int nPaths = array.length();

    for (int i = 0; i < nPaths; i++) {
        JSONArray path = array.getJSONArray(i);
        paths.add(Path.fromJSONArray(path));
    }

    return paths;
}
 
Example 16
Source File: TransferHistoryParser.java    From 1Rramp-Android with MIT License 5 votes vote down vote up
public ArrayList<TransferHistoryModel> parseTransferHistory(String response, String user) {
  ArrayList<TransferHistoryModel> transferHistoryList = new ArrayList<>();
  try {
    JSONObject root = new JSONObject(response);
    JSONObject props = root
      .getJSONObject(KEYS.KEY_RESULT)
      .getJSONObject(KEYS.KEY_PROPS);

    total_vesting_fund_steem = props.getString(KEYS.KEY_TOTAL_VESTING_FUND_STEEM);
    total_vesting_share = props.getString(KEYS.KEY_TOTAL_VESTING_SHARE);

    JSONArray transfer_history = root
      .getJSONObject(KEYS.KEY_RESULT)
      .getJSONObject(KEYS.KEY_ACCOUNTS)
      .getJSONObject(user)
      .getJSONArray(KEYS.KEY_TRANSFER_HISTORY);

    for (int i = 0; i < transfer_history.length(); i++) {
      JSONArray _history_item = transfer_history.getJSONArray(i);
      JSONObject transfer_obj = _history_item.getJSONObject(1);
      JSONArray operationArray = transfer_obj.getJSONArray(KEYS.KEY_OPERATION);
      String timestamp = transfer_obj.getString(KEYS.KEY_TIMESTAMP);
      JSONObject meta_data_obj = operationArray.getJSONObject(1);
      String operation = operationArray.getString(0);
      //skipping extra data
      if (operation.equals(KEYS.OPERATION_CLAIM_REWARD_BALANCE) ||
        operation.equals(KEYS.OPERATION_AUTHOR_REWARD) ||
        operation.equals(KEYS.OPERATION_TRANSFER) ||
        operation.equals(KEYS.OPERATION_CURATION_REWARD)) {
        transferHistoryList.add(parse(user, operation, timestamp, meta_data_obj));
      }
    }
  }
  catch (JSONException e) {
    e.printStackTrace();
  }
  return transferHistoryList;
}
 
Example 17
Source File: JSONObjectUtils.java    From DevUtils with Apache License 2.0 5 votes vote down vote up
/**
 * 获取 JSONArray
 * @param jsonArray {@link JSONArray}
 * @param index     索引
 * @return {@link JSONArray}
 */
public static JSONArray getJSONArray(final JSONArray jsonArray, final int index) {
    try {
        return jsonArray.getJSONArray(index);
    } catch (Exception e) {
        LogPrintUtils.eTag(TAG, e, "getJSONArray");
    }
    return null;
}
 
Example 18
Source File: WebPlayerView.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
protected String doInBackground(Void... voids) {
    String playerCode = downloadUrlContent(this, String.format(Locale.US, "http://www.aparat.com/video/video/embed/vt/frame/showvideo/yes/videohash/%s", videoId));
    if (isCancelled()) {
        return null;
    }
    try {
        Matcher filelist = aparatFileListPattern.matcher(playerCode);
        if (filelist.find()) {
            String jsonCode = filelist.group(1);
            JSONArray json = new JSONArray(jsonCode);
            for (int a = 0; a < json.length(); a++) {
                JSONArray array = json.getJSONArray(a);
                if (array.length() == 0) {
                    continue;
                }
                JSONObject object = array.getJSONObject(0);
                if (!object.has("file")) {
                    continue;
                }
                results[0] = object.getString("file");
                results[1] = "other";
            }
        }
    } catch (Exception e) {
        FileLog.e(e);
    }
    return isCancelled() ? null : results[0];
}
 
Example 19
Source File: PeerManager.java    From jelectrum with MIT License 4 votes vote down vote up
private void addRemotePeers(PrintStream out, Scanner scan)
  throws org.json.JSONException
{
  JSONObject request = new JSONObject();
  request.put("id","get_peer");
  request.put("method", "server.peers.subscribe");
  request.put("params",new JSONArray());

  out.println(request.toString(0));
  out.flush();

  JSONObject reply = new JSONObject(scan.nextLine());

  JSONArray peerList = reply.getJSONArray("result");

  for(int i=0; i<peerList.length(); i++)
  {
    JSONArray p = peerList.getJSONArray(i);
    String host = p.getString(1);
    JSONArray param = p.getJSONArray(2);
    int tcp_port=0;
    int ssl_port=0;
    for(int j=0; j<param.length(); j++)
    {
      String str = param.getString(j);
      if (str.startsWith("s"))
      {
        ssl_port = Integer.parseInt(str.substring(1));
      }
      if (str.startsWith("t"))
      {
        tcp_port = Integer.parseInt(str.substring(1));
      }

    }
    if (tcp_port + ssl_port > 0)
    {
      addPeer(host, tcp_port, ssl_port);
    }

  }

}
 
Example 20
Source File: DotsData.java    From commcare-android with Apache License 2.0 4 votes vote down vote up
public static DotsData DeserializeDotsData(String dots) {

        try {
            JSONObject data = new JSONObject(new JSONTokener(dots));

            Date anchor = new Date(Date.parse(data.getString("anchor")));

            JSONArray jRegs = data.getJSONArray("regimens");
            int[] regs = new int[jRegs.length()];
            for (int i = 0; i < regs.length; ++i) {
                regs[i] = jRegs.getInt(i);
            }

            int[][] regLabels = new int[regs.length][];
            if (data.has("regimen_labels")) {
                JSONArray jRegLabels = data.getJSONArray("regimen_labels");
                if (jRegLabels.length() != regs.length) {
                    //TODO: specific exception type here
                    throw new RuntimeException("Invalid DOTS model! Regimens and Labels are incompatible lengths");
                }
                for (int i = 0; i < jRegLabels.length(); ++i) {
                    JSONArray jLabels = jRegLabels.getJSONArray(i);
                    regLabels[i] = new int[jLabels.length()];
                    for (int j = 0; j < jLabels.length(); ++j) {
                        regLabels[i][j] = jLabels.getInt(j);
                    }
                }
            } else {
                //No default regimen labels
                regLabels = null;
            }

            JSONArray jDays = data.getJSONArray("days");
            DotsDay[] days = new DotsDay[jDays.length()];
            for (int i = 0; i < days.length; ++i) {
                days[i] = DotsDay.deserialize(jDays.getJSONArray(i));
            }

            return new DotsData(anchor, regs, days, regLabels);
        } catch (JSONException e) {
            throw new RuntimeException(e);
        }


    }