Android JsonReader - top ranked examples from Open Source projects

These code examples were ranked by Codota’s semantic indexing as the best open source examples for Android JsonReader class.

This code example shows how to use the following methods:nextBoolean, peek
		return result;
	} 
 
	static Object getValue(JsonReader r) throws IOException {
		Object value = null;
		JsonToken token = r.peek();
 
		switch (token) {
		case NULL:
			r.nextNull();
			break; 
		case BOOLEAN:
			value = r.nextBoolean();
			break; 
		default: 
			value = r.nextString();
		} 
 
		return value;
	} 
7
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:beginObject, endObject, nextName, nextString
   } 
 
   @Override 
   public Header read(JsonReader in) throws IOException {
      Header.Builder builder = new Header.Builder(); 
      in.beginObject();
      in.nextName();
      builder.signerAlgorithm(in.nextString());
      in.nextName();
      builder.type(in.nextString());
      in.endObject();
      return builder.build(); 
   } 
} 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:nextNull, peek
 * */ 
 
public class NetDateTimeAdapter extends TypeAdapter<Date> {
    @Override 
    public Date read(JsonReader reader) throws IOException {
        if (reader.peek() == JsonToken.NULL) {
            reader.nextNull();
            return null; 
        } 
        Date result = null;
        String str = reader.nextString();
        str = str.replaceAll("[^0-9]", "");
        if (!TextUtils.isEmpty(str)) {
            try { 
                result = new Date(Long.parseLong(str));
            } catch (NumberFormatException e) {
            } 
        } 
        return result;
    } 
6
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:isLenient, setLenient
   * @throws JsonParseException if there is an IOException or if the specified 
   *     text is not valid JSON 
   * @since 1.6 
   */ 
  public JsonElement parse(JsonReader json) throws JsonIOException, JsonSyntaxException {
    boolean lenient = json.isLenient();
    json.setLenient(true);
    try { 
      return Streams.parse(json);
    } catch (StackOverflowError e) {
      throw new JsonParseException("Failed parsing JSON source: " + json + " to Json", e);
    } catch (OutOfMemoryError e) {
      throw new JsonParseException("Failed parsing JSON source: " + json + " to Json", e);
    } finally { 
      json.setLenient(lenient);
    } 
  } 
} 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:beginObject, close, nextName
	 * @param in 
	 * @throws Exception 
	 */ 
	public static void readJsonData(InputStream in,String json) throws Exception {
		//JsonReader reader = new JsonReader(new InputStreamReader(in, "UTF-8")); 
		JsonReader reader = new JsonReader(new StringReader(json));
		try { 
			reader.beginObject();
			String tagName = reader.nextName();
			if (tagName.equals("info")) {
				readInfo(reader);
			} 
			reader.endObject();
		} finally { 
			reader.close();
		} 
	} 
	/** 
	 * 读取json的父(根,第一个)节点 
	 * @param reader 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:nextNull, peek
write(writer.value("11"),);
		 
	} 
    public Point read(JsonReader reader) throws IOException {
      if (reader.peek() == JsonToken.NULL) {
        reader.nextNull();
        return null; 
      } 
      String xy = reader.nextString();
      String[] parts = xy.split(",");
      int x = Integer.parseInt(parts[0]);
      int y = Integer.parseInt(parts[1]);
      return new Point(x, y);
    } 
    public void write(JsonWriter writer, Point value) throws IOException {
      if (value == null) {
        writer.nullValue();
        return; 
      } 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:nextNull, peek
 */ 
public final class BigDecimalTypeAdapter extends TypeAdapter<BigDecimal> {
 
  @Override 
  public BigDecimal read(JsonReader in) throws IOException {
    if (in.peek() == JsonToken.NULL) {
      in.nextNull();
      return null; 
    } 
    try { 
      return new BigDecimal(in.nextString());
    } catch (NumberFormatException e) {
      throw new JsonSyntaxException(e);
    } 
  } 
 
  @Override 
  public void write(JsonWriter out, BigDecimal value) throws IOException {
    out.value(value);
  } 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:nextNull, peek
      return iso8601Format.parse(json);
    } catch (ParseException e) {
      throw new JsonSyntaxException(json, e);
    } 
  } 
 
  @Override public synchronized void write(JsonWriter out, Date value) throws IOException {
    if (value == null) {
      out.nullValue();
      return; 
    } 
    String dateFormatAsString = enUsFormat.format(value);
    out.value(dateFormatAsString);
  } 
} 
5
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:hasNext
public class SampleReader { 
 
    static List<Sample> readSamples(Reader reader) {
        final ArrayList<Sample> samples = new ArrayList<Sample>();
 
        final JsonReader jsonReader = new JsonReader(reader);
        try { 
        while (jsonReader.hasNext()) {
                samples.add(JSONUnmarshaller.unmarshall(jsonReader, Sample.class));
        } 
        } catch (Exception e) {
            e.printStackTrace();
        } 
        return  samples;
    } 
} 
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java
This code example shows how to use the following methods:peek
   * Takes a reader in any state and returns the next value as a JsonElement. 
   */ 
  public static JsonElement parse(JsonReader reader) throws JsonParseException {
    boolean isEmpty = true;
    try { 
      reader.peek();
      isEmpty = false;
      return TypeAdapters.JSON_ELEMENT.read(reader);
    } catch (EOFException e) {
      /* 
       * For compatibility with JSON 1.5 and earlier, we return a JsonNull for 
       * empty documents instead of throwing. 
       */ 
      if (isEmpty) {
        return JsonNull.INSTANCE;
      } 
      // The stream ended prematurely so it is likely a syntax error. 
      throw new JsonSyntaxException(e);
    } catch (MalformedJsonException e) {
      throw new JsonSyntaxException(e);
4
CodeRank
Connect your IDE to all the code out there  Get Codota for Java

Related Android JsonReader Questions & Answers:

See Code Examples for Android JsonReader Methods: