Example usage for org.json JSONObject getJSONArray

List of usage examples for org.json JSONObject getJSONArray

Introduction

In this page you can find the example usage for org.json JSONObject getJSONArray.

Prototype

public JSONArray getJSONArray(String key) throws JSONException 

Source Link

Document

Get the JSONArray value associated with a key.

Usage

From source file:com.cssweb.android.view.KlineViewSingle.java

public void drawOBV(Canvas canvas, JSONObject quoteData, int begin, int count, double shapeWidth,
        double spaceWidth, double highPrice, double lowPrice, double highVolume, int actualDataLen)
        throws JSONException {
    //      this.shapeWidth = shapeWidth;
    //      this.spaceWidth = spaceWidth;
    if (quoteData.isNull("OBV") || quoteData.getJSONArray("OBV").length() < 1) {
        isNetworkErrorDisplay();/*from w  ww . j a  v a2 s.c  o  m*/
        return;
    }
    long max = 1;
    long min = 99999999999999l;
    long obv, maobv;
    int len = quoteData.getJSONArray("OBV").length();
    for (int i = begin; i < (begin + count) && i < len; i++) {
        obv = quoteData.getJSONArray("OBV").getJSONArray(i).getLong(1);
        maobv = quoteData.getJSONArray("OBV").getJSONArray(i).getLong(2);
        max = Arith.max(obv, maobv, max);
        min = Arith.min(obv, maobv, min);
    }
    max = max + (max - min) / 10;
    min = min - (max - min) / 10;
    double scale = (double) (this.volumeHeight) / (max - min);

    int startX = klineX;
    int startY = klineY;

    double AxisLabelVolume = max;
    String lblvalue = "12345";
    int ratiolen = String.valueOf(Math.round(AxisLabelVolume)).length() - String.valueOf(lblvalue).length();

    String labelRatio = "";
    int scaleVol = 1;
    switch (ratiolen) {
    case 1:
        labelRatio = "x10";
        scaleVol = 10;
        break;
    case 2:
        labelRatio = "x100";
        scaleVol = 100;
        break;
    case 3:
        labelRatio = "x1000";
        scaleVol = 1000;
        break;
    case 4:
        labelRatio = "x10000";
        scaleVol = 10000;
        break;
    case 5:
        labelRatio = "x1";
        scaleVol = 1000000;
        break;
    case 6:
        labelRatio = "x1";
        scaleVol = 1000000;
        break;
    default:
        labelRatio = "x1";
        scaleVol = 1;
        break;
    }

    int axisY1 = (int) (startY + volumeHeight - (max - min) * scale);
    paint.setColor(GlobalColor.clrLine);
    Graphics.drawDashline(canvas, startX, axisY1, width, axisY1, paint);

    String axisLabel1 = String.valueOf((int) max / scaleVol);

    int axisY2 = (int) (startY + volumeHeight - (max - min) * 3 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY2, width, axisY2, paint);

    String axisLabel2 = String.valueOf((int) (min + (max - min) * 3 / 4) / scaleVol);

    int axisY3 = (int) (startY + volumeHeight - (max - min) * 2 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY3, width, axisY3, paint);

    String axisLabel3 = String.valueOf((int) (min + (max - min) * 2 / 4) / scaleVol);

    int axisY4 = (int) (startY + volumeHeight - (max - min) / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY4, width, axisY4, paint);

    String axisLabel4 = String.valueOf((int) (min + (max - min) * 1 / 4) / scaleVol);

    if (isTrackStatus == false) {
        tPaint.setColor(GlobalColor.colorKlabel);
        canvas.drawText(labelRatio, startX - tips / 4, startY + volumeHeight + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel1, startX - tips / 4, axisY1 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel2, startX - tips / 4, axisY2 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel3, startX - tips / 4, axisY3 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel4, startX - tips / 4, axisY4 + axisLabelHeight / 2, tPaint);
    }
    canvas.drawLine(startX, height - axisLabelHeight, width, height - axisLabelHeight, paint);

    if (quoteData != null) {
        double currX = 0, currY1 = 0, currY2 = 0;//???
        double nextX = 0, nextY1 = 0, nextY2 = 0;//??

        int kHeight = 0;

        for (int i = begin; i < (begin + count) && i < len; i++) {
            obv = quoteData.getJSONArray("OBV").getJSONArray(i).getLong(1);
            maobv = quoteData.getJSONArray("OBV").getJSONArray(i).getLong(2);

            startX = klineX;

            if ((i - begin) == 0) {
                currX = 0;
                currX = nextX = currX + startX + spaceWidth + shapeWidth / 2;
                kHeight = (int) ((obv - min) * scale);
                currY1 = nextY1 = startY + volumeHeight - kHeight;
                kHeight = (int) ((maobv - min) * scale);
                currY2 = nextY2 = startY + volumeHeight - kHeight;
            } else {
                nextX = currX + spaceWidth + shapeWidth;
            }
            // obv
            kHeight = (int) ((obv - min) * scale);
            nextY1 = startY + volumeHeight - kHeight;
            paint.setColor(GlobalColor.colorM5);
            canvas.drawLine((int) currX, (int) currY1, (int) nextX, (int) nextY1, paint);

            // maobv
            kHeight = (int) ((maobv - min) * scale);
            nextY2 = startY + volumeHeight - kHeight;
            paint.setColor(GlobalColor.colorM10);
            canvas.drawLine((int) currX, (int) currY2, (int) nextX, (int) nextY2, paint);

            currX = nextX;
            currY1 = nextY1;
            currY2 = nextY2;

            if (i == (begin + count - 1)) {

            }
        } // end for
    } // end if
}

From source file:com.cssweb.android.view.KlineViewSingle.java

public void drawROC(Canvas canvas, JSONObject quoteData, int begin, int count, double shapeWidth,
        double spaceWidth, double highPrice, double lowPrice, double highVolume, int actualDataLen,
        String indicator) throws JSONException {
    this.shapeWidth = shapeWidth;
    this.spaceWidth = spaceWidth;
    if (quoteData.isNull(indicator) || quoteData.getJSONArray(indicator).length() < 1) {
        isNetworkErrorDisplay();// ww w.j a v  a  2 s.  co  m
        return;
    }
    double max = 0.001;
    double min = 9999999999f;
    double wr = 0, wr2 = 0;
    int len = quoteData.getJSONArray(indicator).length();
    for (int i = begin; i < (begin + count) && i < len; i++) {
        wr = quoteData.getJSONArray(indicator).getJSONArray(i).getDouble(1);
        wr2 = quoteData.getJSONArray(indicator).getJSONArray(i).getDouble(2);
        max = Arith.max(wr, wr2, max);
        min = Arith.min(wr, wr2, min);
    }
    max = max * 1.1;
    min = min - Math.abs(min) * 0.1;
    double scale = (double) (this.volumeHeight) / (max - min);

    int startX = klineX;
    int startY = klineY;

    double AxisLabelVolume = max;
    String lblvalue = "12345";
    int ratiolen = String.valueOf(Math.round(AxisLabelVolume)).length() - String.valueOf(lblvalue).length();

    String labelRatio = "";
    int scaleVol = 1;
    switch (ratiolen) {
    case 1:
        labelRatio = "x10";
        scaleVol = 10;
        break;
    case 2:
        labelRatio = "x100";
        scaleVol = 100;
        break;
    case 3:
        labelRatio = "x1000";
        scaleVol = 1000;
        break;
    case 4:
        labelRatio = "x10000";
        scaleVol = 10000;
        break;
    default:
        labelRatio = "";
        scaleVol = 1;
        break;
    }

    int axisY1 = (int) (startY + volumeHeight - (max - min) * scale);
    paint.setColor(GlobalColor.clrLine);
    Graphics.drawDashline(canvas, startX, axisY1, width, axisY1, paint);

    String axisLabel1 = Utils.dataFormation(max / scaleVol, 1);

    int axisY2 = (int) (startY + volumeHeight - (max - min) * 3 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY2, width, axisY2, paint);

    String axisLabel2 = Utils.dataFormation((min + (max - min) * 3 / 4) / scaleVol, 1);

    int axisY3 = (int) (startY + volumeHeight - (max - min) * 2 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY3, klineX + klineWidth, axisY3, paint);

    String axisLabel3 = Utils.dataFormation((min + (max - min) * 2 / 4) / scaleVol, 1);

    int axisY4 = (int) (startY + volumeHeight - (max - min) / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY4, klineX + klineWidth, axisY4, paint);

    String axisLabel4 = Utils.dataFormation((min + (max - min) * 1 / 4) / scaleVol, 1);

    if (isTrackStatus == false) {
        tPaint.setColor(GlobalColor.colorKlabel);
        canvas.drawText(labelRatio, startX - tips / 4, startY + volumeHeight + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel1, startX - tips / 4, axisY1 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel2, startX - tips / 4, axisY2 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel3, startX - tips / 4, axisY3 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel4, startX - tips / 4, axisY4 + axisLabelHeight / 2, tPaint);
    }

    canvas.drawLine(startX, height - axisLabelHeight, width, height - axisLabelHeight, paint);

    if (quoteData != null) {
        double currX = 0, currY1 = 0, currY2 = 0;//???
        double nextX = 0, nextY1 = 0, nextY2 = 0;//??

        int kHeight = 0;

        for (int i = begin; i < (begin + count) && i < len; i++) {
            wr = quoteData.getJSONArray(indicator).getJSONArray(i).getDouble(1);
            wr2 = quoteData.getJSONArray(indicator).getJSONArray(i).getDouble(2);

            if ((i - begin) == 0) {
                currX = startX;
                currX = nextX = currX + spaceWidth + shapeWidth / 2;
                kHeight = (int) ((wr - min) * scale);
                currY1 = nextY1 = startY + volumeHeight - kHeight;

                kHeight = (int) ((wr2 - min) * scale);
                currY2 = nextY2 = startY + volumeHeight - kHeight;
            } else {
                nextX = currX + spaceWidth + shapeWidth;
                kHeight = (int) ((wr - min) * scale);
                nextY1 = startY + volumeHeight - kHeight;

                kHeight = (int) ((wr2 - min) * scale);
                nextY2 = startY + volumeHeight - kHeight;
            }
            paint.setColor(GlobalColor.colorM5);
            canvas.drawLine((float) currX, (float) currY1, (float) nextX, (float) nextY1, paint);

            paint.setColor(GlobalColor.colorM10);
            canvas.drawLine((float) currX, (float) currY2, (float) nextX, (float) nextY2, paint);

            currX = nextX;
            currY1 = nextY1;
            currY2 = nextY2;

            if (i == (begin + count - 1)) {

            }
        } // end for
    } // end if
}

From source file:com.cssweb.android.view.KlineViewSingle.java

public void drawOther(Canvas canvas, JSONObject quoteData, int begin, int count, double shapeWidth,
        double spaceWidth, double highPrice, double lowPrice, double highVolume, int actualDataLen,
        String indicator) throws JSONException {
    this.shapeWidth = shapeWidth;
    this.spaceWidth = spaceWidth;
    if (quoteData.isNull(indicator) || quoteData.getJSONArray(indicator).length() < 1) {
        isNetworkErrorDisplay();/*  ww w  . j a v  a  2  s  .co m*/
        return;
    }
    double max = 0.001;
    double min = 9999999999f;
    double wr = 0, wr2 = 0;
    int len = quoteData.getJSONArray(indicator).length();
    for (int i = begin; i < (begin + count) && i < len; i++) {
        wr = quoteData.getJSONArray(indicator).getJSONArray(i).getDouble(1);
        wr2 = quoteData.getJSONArray(indicator).getJSONArray(i).getDouble(2);
        max = Arith.max(wr, wr2, max);
        min = Arith.min(wr, wr2, min);
    }
    max = max + (max - min) / 10;
    min = min - (max - min) / 10;
    double scale = (double) (this.volumeHeight) / (max - min);

    int startX = klineX;
    int startY = klineY;

    double AxisLabelVolume = max;
    String lblvalue = "12345";
    int ratiolen = String.valueOf(Math.round(AxisLabelVolume)).length() - String.valueOf(lblvalue).length();

    String labelRatio = "";
    int scaleVol = 1;
    switch (ratiolen) {
    case 1:
        labelRatio = "x10";
        scaleVol = 10;
        break;
    case 2:
        labelRatio = "x100";
        scaleVol = 100;
        break;
    case 3:
        labelRatio = "x1000";
        scaleVol = 1000;
        break;
    case 4:
        labelRatio = "x10000";
        scaleVol = 10000;
        break;
    default:
        labelRatio = "";
        scaleVol = 1;
        break;
    }

    int axisY1 = (int) (startY + volumeHeight - (max - min) * scale);
    paint.setColor(GlobalColor.clrLine);
    Graphics.drawDashline(canvas, startX, axisY1, width, axisY1, paint);

    String axisLabel1 = String.valueOf((int) max / scaleVol);

    int axisY2 = (int) (startY + volumeHeight - (max - min) * 3 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY2, width, axisY2, paint);

    String axisLabel2 = String.valueOf((int) (min + (max - min) * 3 / 4) / scaleVol);

    int axisY3 = (int) (startY + volumeHeight - (max - min) * 2 / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY3, klineX + klineWidth, axisY3, paint);

    String axisLabel3 = String.valueOf((int) (min + (max - min) * 2 / 4) / scaleVol);

    int axisY4 = (int) (startY + volumeHeight - (max - min) / 4 * scale);
    Graphics.drawDashline(canvas, startX, axisY4, klineX + klineWidth, axisY4, paint);

    String axisLabel4 = String.valueOf((int) (min + (max - min) * 1 / 4) / scaleVol);

    if (isTrackStatus == false) {
        tPaint.setColor(GlobalColor.colorKlabel);
        canvas.drawText(labelRatio, startX - tips / 4, startY + volumeHeight + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel1, startX - tips / 4, axisY1 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel2, startX - tips / 4, axisY2 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel3, startX - tips / 4, axisY3 + axisLabelHeight / 2, tPaint);
        canvas.drawText(axisLabel4, startX - tips / 4, axisY4 + axisLabelHeight / 2, tPaint);
    }

    canvas.drawLine(startX, height - axisLabelHeight, width, height - axisLabelHeight, paint);

    if (quoteData != null) {
        double currX = 0, currY1 = 0, currY2 = 0;//???
        double nextX = 0, nextY1 = 0, nextY2 = 0;//??

        int kHeight = 0;

        for (int i = begin; i < (begin + count) && i < len; i++) {
            wr = quoteData.getJSONArray(indicator).getJSONArray(i).getLong(1);
            wr2 = quoteData.getJSONArray(indicator).getJSONArray(i).getLong(2);

            if ((i - begin) == 0) {
                currX = startX;
                currX = nextX = currX + spaceWidth + shapeWidth / 2;
                kHeight = (int) ((wr - min) * scale);
                currY1 = nextY1 = startY + volumeHeight - kHeight;

                kHeight = (int) ((wr2 - min) * scale);
                currY2 = nextY2 = startY + volumeHeight - kHeight;
            } else {
                nextX = currX + spaceWidth + shapeWidth;
                kHeight = (int) ((wr - min) * scale);
                nextY1 = startY + volumeHeight - kHeight;

                kHeight = (int) ((wr2 - min) * scale);
                nextY2 = startY + volumeHeight - kHeight;
            }
            paint.setColor(GlobalColor.colorM5);
            canvas.drawLine((float) currX, (float) currY1, (float) nextX, (float) nextY1, paint);

            paint.setColor(GlobalColor.colorM10);
            canvas.drawLine((float) currX, (float) currY2, (float) nextX, (float) nextY2, paint);

            currX = nextX;
            currY1 = nextY1;
            currY2 = nextY2;

            if (i == (begin + count - 1)) {

            }
        } // end for
    } // end if
}

From source file:ai.susi.mind.SusiReader.java

public SusiReader learn(JSONObject json) {

    // initialize temporary json objects
    JSONObject syn = json.has("synonyms") ? json.getJSONObject("synonyms") : new JSONObject();
    JSONArray fill = json.has("filler") ? json.getJSONArray("filler") : new JSONArray();
    JSONObject cat = json.has("categories") ? json.getJSONObject("categories") : new JSONObject();

    // add synonyms
    for (String canonical : syn.keySet()) {
        JSONArray a = syn.getJSONArray(canonical);
        a.forEach(synonym -> synonyms.put(((String) synonym).toLowerCase(), canonical));
    }/*from  w  w  w  .j av a 2s .c  om*/

    // add filler
    fill.forEach(word -> filler.add((String) word));

    // add categories
    for (String canonical : cat.keySet()) {
        JSONArray a = cat.getJSONArray(canonical);
        a.forEach(synonym -> categories.put(((String) synonym).toLowerCase(), canonical));
    }

    return this;
}

From source file:org.loklak.api.iot.OpenWifiMapPushServlet.java

@Override
protected JSONArray extractMessages(JSONObject data) {
    return data.getJSONArray("rows");
}

From source file:br.com.indigo.android.facebook.SocialFacebook.java

private void handleFeedResponse(JSONObject jsonResponse, FeedListener listener) {
    FbSimplePost post;// w w  w. ja va 2 s.co m
    ArrayList<FbSimplePost> posts = new ArrayList<FbSimplePost>();

    try {
        JSONArray objs = jsonResponse.getJSONArray("data");

        for (int i = 0; i < objs.length(); i++) {
            JSONObject obj = objs.getJSONObject(i);

            post = new FbSimplePost();
            post.setId(obj.getString("id"));

            JSONObject fromJson = obj.optJSONObject("from");
            if (fromJson != null) {
                FbSimpleUser from = new FbSimpleUser();
                from.setId(fromJson.getString("id"));
                from.setName(fromJson.getString("name"));

                post.setFrom(from);
            }

            post.setMessage(obj.optString("message"));
            post.setPicture(obj.optString("picture"));
            post.setLink(obj.optString("link"));
            post.setName(obj.optString("name"));
            post.setCaption(obj.optString("caption"));
            post.setDescription(obj.optString("description"));
            post.setSource(obj.optString("source"));
            post.setType(obj.optString("type"));

            post.setCreatedTime(new Date(obj.getLong("created_time")));
            post.setUpdatedTime(new Date(obj.getLong("updated_time")));

            JSONObject comments = obj.optJSONObject("comments");
            if (comments != null) {
                post.setNumberOfComments(comments.getInt("count"));
            }

            JSONObject likes = obj.optJSONObject("likes");
            if (likes != null) {
                post.setNumberOfLikes(likes.getInt("count"));
            }

            posts.add(post);
        }

        String nextPage = null;
        JSONObject paging = jsonResponse.optJSONObject("paging");
        if (paging != null) {
            nextPage = paging.optString("next");
        }

        listener.onComplete(posts, nextPage);

    } catch (JSONException e) {
        Util.logd(TAG, "Could not parse Json response", e);
        listener.onFail(e);
    }
}

From source file:br.com.indigo.android.facebook.SocialFacebook.java

private void handleUsersResponse(JSONObject jsonResponse, UsersListener listener) {

    FbSimpleUser user = null;//from  w  w  w . j a  va  2 s.  co  m
    ArrayList<FbSimpleUser> friends = new ArrayList<FbSimpleUser>();

    try {
        JSONArray objs = jsonResponse.getJSONArray("data");

        for (int i = 0; i < objs.length(); i++) {
            JSONObject obj = objs.getJSONObject(i);

            user = new FbSimpleUser();
            user.setId(obj.getString("id"));
            user.setName(obj.getString("name"));

            String rsvpStatus = obj.optString("rsvp_status");

            if (rsvpStatus != null) {
                if (rsvpStatus.equals("not_replied")) {
                    user.setRSVPStatus(RSVP_STATUS.NOT_REPLIED);
                } else if (rsvpStatus.equals("attending")) {
                    user.setRSVPStatus(RSVP_STATUS.ATTENDING);
                } else if (rsvpStatus.equals("declined")) {
                    user.setRSVPStatus(RSVP_STATUS.DECLINED);
                } else if (rsvpStatus.equals("unsure")) {
                    user.setRSVPStatus(RSVP_STATUS.MAYBE);
                }
            }

            friends.add(user);
        }

        String nextPage = null;
        JSONObject paging = jsonResponse.optJSONObject("paging");
        if (paging != null) {
            nextPage = paging.optString("next");
        }

        listener.onComplete(friends, nextPage);

    } catch (JSONException e) {
        Util.logd(TAG, "Could not parse Json response", e);
        listener.onFail(e);
    }
}

From source file:br.com.indigo.android.facebook.SocialFacebook.java

private void handleEventsResponse(JSONObject jsonResponse, EventsListener listener) {

    ArrayList<FbEvent> events = new ArrayList<FbEvent>();

    try {/*from w  ww  . jav  a  2  s .c  o m*/
        JSONArray objs = jsonResponse.getJSONArray("data");

        for (int i = 0; i < objs.length(); i++) {
            JSONObject obj = objs.getJSONObject(i);

            events.add(parseEvent(obj));
        }

        String nextPage = null;
        JSONObject paging = jsonResponse.optJSONObject("paging");
        if (paging != null) {
            nextPage = paging.optString("next");
        }

        listener.onComplete(events, nextPage);

    } catch (JSONException e) {
        Util.logd(TAG, "Could not parse Json response", e);
        listener.onFail(e);
    }
}

From source file:br.com.indigo.android.facebook.SocialFacebook.java

private void handleCommentsResponse(JSONObject jsonResponse, CommentsListener listener) {

    FbComment comment = null;// w  w  w  . ja va 2s  .  co m
    ArrayList<FbComment> comments = new ArrayList<FbComment>();

    try {
        JSONArray objs = jsonResponse.getJSONArray("data");

        for (int i = 0; i < objs.length(); i++) {
            JSONObject obj = objs.getJSONObject(i);

            comment = new FbComment();
            comment.setId(obj.getString("id"));
            comment.setMessage(obj.optString("message"));
            comment.setCreatedTime(new Date(obj.optLong("created_time") * 1000));
            comment.setNumberOfLikes(obj.optInt("likes"));

            JSONObject fromJson = obj.optJSONObject("from");
            if (fromJson != null) {
                FbSimpleUser fromUser = new FbSimpleUser();
                fromUser.setId(fromJson.getString("id"));
                fromUser.setName(fromJson.optString("name"));

                comment.setFrom(fromUser);
            }

            comments.add(comment);
        }

        String nextPage = null;
        JSONObject paging = jsonResponse.optJSONObject("paging");
        if (paging != null) {
            nextPage = paging.optString("next");
        }

        listener.onComplete(comments, nextPage);

    } catch (JSONException e) {
        Util.logd(TAG, "Could not parse Json response", e);
        listener.onFail(e);
    }
}

From source file:com.ledger.android.u2f.bridge.MainActivity.java

private U2FContext parseU2FContextSign(JSONObject json) {
    try {/* ww  w  . j a va 2s .  co  m*/
        String appId = json.getString(TAG_JSON_APPID);
        byte[] challenge = Base64.decode(json.getString(TAG_JSON_CHALLENGE), Base64.URL_SAFE);
        int requestId = json.getInt(TAG_JSON_REQUESTID);
        JSONArray array = json.getJSONArray(TAG_JSON_REGISTERED_KEYS);
        Vector<byte[]> keyHandles = new Vector<byte[]>();
        for (int i = 0; i < array.length(); i++) {
            JSONObject keyHandleItem = array.getJSONObject(i);
            if (!keyHandleItem.getString(TAG_JSON_VERSION).equals(VERSION_U2F_V2)) {
                Log.e(TAG, "Invalid handle version");
                return null;
            }
            byte[] keyHandle = Base64.decode(keyHandleItem.getString(TAG_JSON_KEYHANDLE), Base64.URL_SAFE);
            keyHandles.add(keyHandle);
        }
        return new U2FContext(appId, challenge, keyHandles, requestId, true);
    } catch (JSONException e) {
        Log.e(TAG, "Error decoding request");
        return null;
    }
}