Example usage for android.util JsonReader nextString

List of usage examples for android.util JsonReader nextString

Introduction

In this page you can find the example usage for android.util JsonReader nextString.

Prototype

public String nextString() throws IOException 

Source Link

Document

Returns the JsonToken#STRING string value of the next token, consuming it.

Usage

From source file:com.workday.autoparse.json.parser.JsonParserUtils.java

public static String nextString(JsonReader reader, String name) throws IOException {
    if (handleNull(reader)) {
        return null;
    }//www  . j av a2 s  . c o  m
    assertType(reader, name, JsonToken.STRING, JsonToken.NUMBER, JsonToken.BOOLEAN);

    if (reader.peek() == JsonToken.BOOLEAN) {
        return String.valueOf(reader.nextBoolean());
    }

    return reader.nextString();
}

From source file:com.tcity.android.ui.info.BuildInfoTask.java

@Nullable
private String getAgentName(@NotNull JsonReader reader) throws IOException {
    reader.beginObject();/*from   w w  w . ja  v  a 2 s  .  c  o  m*/

    String result = null;

    while (reader.hasNext()) {
        switch (reader.nextName()) {
        case "name":
            result = reader.nextString();
            break;
        default:
            reader.skipValue();
        }
    }

    reader.endObject();

    return result;
}

From source file:com.tcity.android.ui.info.BuildArtifactsTask.java

@Nullable
private String getHref(@NotNull JsonReader reader) throws IOException {
    reader.beginObject();//from  w w w  .j a va 2s . c om

    String result = null;

    while (reader.hasNext()) {
        switch (reader.nextName()) {
        case "href":
            result = reader.nextString();
            break;
        default:
            reader.skipValue();
        }
    }

    reader.endObject();

    return result;
}

From source file:org.opensilk.music.ui2.loader.PluginLoader.java

public List<ComponentName> readDisabledPlugins() {
    List<ComponentName> list = new ArrayList<>();
    String json = settings.getString(PREF_DISABLED_PLUGINS, null);
    Timber.v("Read disabled plugins=" + json);
    if (json != null) {
        JsonReader jr = new JsonReader(new StringReader(json));
        try {/*from   w  w  w  .  ja  v  a 2  s  .co m*/
            jr.beginArray();
            while (jr.hasNext()) {
                list.add(ComponentName.unflattenFromString(jr.nextString()));
            }
            jr.endArray();
        } catch (IOException e) {
            settings.remove(PREF_DISABLED_PLUGINS);
            list.clear();
        } finally {
            IOUtils.closeQuietly(jr);
        }
    }
    return list;
}

From source file:com.thingsee.tracker.REST.KiiBucketRequestAsyncTask.java

private JSONObject readSingleData(JsonReader jsonReader) throws IOException, JSONException {
    JSONObject jsonObject = new JSONObject();
    jsonReader.beginObject();/*from   w w  w  .  j av  a 2 s .c  om*/
    JsonToken token;
    do {
        String name = jsonReader.nextName();
        if ("sId".equals(name)) {
            jsonObject.put("sId", jsonReader.nextString());
        } else if ("val".equals(name)) {
            jsonObject.put("val", jsonReader.nextDouble());
        } else if ("ts".equals(name)) {
            jsonObject.put("ts", jsonReader.nextLong());
        } else if ("_owner".equals(name)) {
            jsonObject.put("_owner", jsonReader.nextString());
        }

        token = jsonReader.peek();
    } while (token != null && !token.equals(JsonToken.END_OBJECT));
    jsonReader.endObject();
    return jsonObject;
}

From source file:com.example.propertylist.handler.JsonPropertyHandler.java

/**
 * Loads the next observation into the property class.
 *
 * @param reader/*from w  w  w. j a  v a2s  .c o  m*/
 *            the {@link android.util.JsonReader} containing the observation
 * @throws java.io.IOException
 */
private Property parseSalesData(JsonReader reader) throws IOException {
    Property property = new Property();
    reader.beginObject();
    while (reader.hasNext()) {
        String name = reader.nextName();
        if (name.equals("full_address") && reader.peek() != JsonToken.NULL) {
            property.setFullAddress(reader.nextString());
        } else if (name.equals("daft_url") && reader.peek() != JsonToken.NULL) {
            property.setDaftPropertyUrl(reader.nextString());
        } else if (name.equals("description") && reader.peek() != JsonToken.NULL) {
            property.setDescription(reader.nextString());
        } else if (name.equals("small_thumbnail_url") && reader.peek() != JsonToken.NULL) {
            property.setThumbnailUrl(reader.nextString());
        } else if (name.equals("medium_thumbnail_url") && reader.peek() != JsonToken.NULL) {
            property.setMediumThumbnailUrl(reader.nextString());
        } else if (name.equals("large_thumbnail_url") && reader.peek() != JsonToken.NULL) {
            property.setLargeThumbnailUrl(reader.nextString());
        } else {
            reader.skipValue();
        } // end if hasnext
    } // end while
    reader.endObject();
    return property;
}

From source file:pedromendes.tempodeespera.HospitalDetailActivity.java

private void readEmergency(JsonReader reader, Emergency hospitalEmergencyDetail) throws IOException {
    while (reader.hasNext()) {
        String fieldDame = reader.nextName();
        if (fieldDame.equals("Emergency")) {
            reader.beginObject();//from   w  w  w. jav a2  s  .  c o  m
            reader.nextName();
            reader.nextString();
            reader.nextName();
            hospitalEmergencyDetail.setDescription(reader.nextString());
            reader.endObject();
        } else if (fieldDame.equals("Queue") && reader.peek() != JsonToken.NULL) {
            reader.beginObject();
            reader.nextName();
            reader.nextString();
            reader.nextName();
            hospitalEmergencyDetail.setName(reader.nextString());
            reader.endObject();
        } else if (fieldDame.equals("Red")) {
            reader.beginObject();
            fillQueue(reader, hospitalEmergencyDetail.getRedQueue());
            reader.endObject();
        } else if (fieldDame.equals("Orange")) {
            reader.beginObject();
            fillQueue(reader, hospitalEmergencyDetail.getOrangeQueue());
            reader.endObject();
        } else if (fieldDame.equals("Yellow")) {
            reader.beginObject();
            fillQueue(reader, hospitalEmergencyDetail.getYellowQueue());
            reader.endObject();
        } else if (fieldDame.equals("Green")) {
            reader.beginObject();
            fillQueue(reader, hospitalEmergencyDetail.getGreenQueue());
            reader.endObject();
        } else if (fieldDame.equals("Blue")) {
            reader.beginObject();
            fillQueue(reader, hospitalEmergencyDetail.getBlueQueue());
            reader.endObject();
        } else if (fieldDame.equals("LastUpdate")) {
            hospitalEmergencyDetail.setLastUpdate(reader.nextString());
        } else {
            reader.skipValue();
        }
    }
}

From source file:com.workday.autoparse.json.demo.ParserAnnotatedObjectParser.java

private void parseFromReader(ParserAnnotatedObject out, JsonReader reader) throws IOException {
    final String discriminationName = ContextHolder.getContext().getSettings().getDiscriminationName();
    while (reader.hasNext()) {
        String name = reader.nextName();
        if (discriminationName.equals(name)) {
            out.discriminationValue = JsonParserUtils.nextString(reader, discriminationName);
            continue;
        }/*from   w  ww .  j a v a2 s. c o m*/

        switch (name) {
        case "string": {
            out.string = reader.nextString();
            break;
        }
        default: {
            reader.skipValue();
        }
        }
    }
}

From source file:com.fuzz.android.limelight.util.JSONTool.java

/**
 * @param reader/*  ww w .  j  av  a  2  s .co m*/
 * @return the generated ChapterTransition object from JSON
 * @throws IOException
 */
public static ChapterTransition readTransition(JsonReader reader) throws IOException {
    long time = -1;
    int itemPosition = -1;
    int childId = -1;
    int anchorId = -1;
    String message = null;
    int messageResId = -1;
    int grapicResID = -1;
    boolean isActionBarItem = false;
    double xOffset = -1;
    double yOffset = -1;
    int textColor = -1;
    int textBackgroundColor = -1;
    float textSize = -1;
    boolean textBackgroundTransparent = false;
    String animation = null;

    while (reader.hasNext()) {
        try {
            String name = reader.nextName();
            if (name.equals("time"))
                time = reader.nextLong();
            else if (name.equals("item_position"))
                itemPosition = reader.nextInt();
            else if (name.equals("child_id"))
                childId = reader.nextInt();
            else if (name.equals("id"))
                anchorId = reader.nextInt();
            else if (name.equals("message"))
                message = reader.nextString();
            else if (name.equals("message_res_id"))
                messageResId = reader.nextInt();
            else if (name.equals("graphic_res_id"))
                grapicResID = reader.nextInt();
            else if (name.equals("is_action_bar_item"))
                isActionBarItem = reader.nextBoolean();
            else if (name.equals("x_offset"))
                xOffset = reader.nextDouble();
            else if (name.equals("y_offset"))
                yOffset = reader.nextDouble();
            else if (name.equals("text_color"))
                textColor = reader.nextInt();
            else if (name.equals("text_background_color"))
                textBackgroundColor = reader.nextInt();
            else if (name.equals("text_size"))
                textSize = reader.nextLong();
            else if (name.equals("text_background_transparent"))
                textBackgroundTransparent = reader.nextBoolean();
            else if (name.equals("animation"))
                animation = reader.nextString();
        } catch (IllegalStateException e) {
            reader.nextNull();
            e.printStackTrace();
        }
    }

    reader.endObject();

    ChapterTransition transition = new ChapterTransition();
    transition.setTime(time);
    transition.setItemPosition(itemPosition);
    transition.setChildID(childId);
    transition.setId(anchorId);
    transition.setMessage(message);
    transition.setMessageResID(messageResId);
    transition.setGraphicResID(grapicResID);
    transition.setIsActionBarItem(isActionBarItem);
    transition.setDisplacement(xOffset, yOffset);
    transition.setTextColor(textColor);
    transition.setTextBackgroundColor(textBackgroundColor);
    transition.setTextSize(textSize);
    transition.setTransparentBackground(textBackgroundTransparent);
    transition.setAnimation(animation);

    return transition;
}

From source file:at.ac.tuwien.caa.docscan.logic.DataLog.java

private GPS readGPS(JsonReader reader) throws IOException {

    String longitude = null;/*from w w  w  . jav a 2  s  .  co m*/
    String latitude = null;

    reader.beginObject();
    //        reader.beginArray();
    while (reader.hasNext()) {
        String name = reader.nextName();
        if (name.equals(GPS_LONGITUDE_NAME))
            longitude = reader.nextString();
        else if (name.equals(GPS_LATITUDE_NAME))
            latitude = reader.nextString();
        else
            reader.skipValue();
    }
    //        reader.endArray();
    reader.endObject();

    GPS gps = null;
    if (longitude != null && latitude != null)
        gps = new GPS(longitude, latitude);

    return gps;

}