Android JsonWriter - 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 JsonWriter class.

This code example shows how to use the following methods:beginArray, close, endArray, flush
                    if (mJsonWriter == null) return null;
                    // TODO: This is necessary to avoid an exception.  Better would be to not even 
                    // open the JsonWriter if the file is not even opened unless there is valid data 
                    // to write. 
                    if (!mHasWrittenData) {
                        mJsonWriter.beginArray();
                    } 
                    mJsonWriter.endArray();
                    mHasWrittenData = false;
                    mJsonWriter.flush();
                    mJsonWriter.close();
                    if (DEBUG) {
                        Log.d(TAG, "closed " + mFile);
                    } 
                } catch (final Exception e) {
                    Log.d(TAG, "error when closing ResearchLog:", e);
                } finally { 
                    // Marking the file as read-only signals that this log file is ready to be 
                    // uploaded. 
                    if (mFile != null && mFile.exists()) {
5
CodeRank
This code example shows how to use the following methods:flush
    } 
 
    private final Callable<Object> mFlushCallable = new Callable<Object>() {
        @Override 
        public Object call() throws Exception { 
            if (mJsonWriter != null) mJsonWriter.flush(); 
            return null; 
        } 
    }; 
 
    private ScheduledFuture<Object> mFlushFuture;
 
    private void removeAnyScheduledFlush() { 
        if (mFlushFuture != null) {
            mFlushFuture.cancel(false);
            mFlushFuture = null;
        } 
    } 
 
    private void scheduleFlush() { 
5
CodeRank
This code example shows how to use the following methods:beginObject, endObject, name
                type = TYPE_BOOLEAN;
            } 
        } 
 
        public void toJSON(JsonWriter writer) throws IOException {
            writer.beginObject();
            writer.name("name").value(name);
            writer.name("type").value(getTypeString());
            writer.endObject();
        } 
    } 
} 
5
CodeRank
This code example shows how to use the following methods:beginObject, endObject, name
        return 0; 
    } 
 
    @Override 
    public void serializeRepresentation(JsonWriter writer) throws IOException {
        writer.beginObject();
        writer.name(SERIALIZATION_STRAIGHTEN_VALUE).value(mStraighten);
        writer.endObject();
    } 
 
    @Override 
    public void deSerializeRepresentation(JsonReader reader) throws IOException {
        boolean unset = true;
        reader.beginObject();
        while (reader.hasNext()) {
            String name = reader.nextName();
            if (SERIALIZATION_STRAIGHTEN_VALUE.equals(name)) {
                float s = (float) reader.nextDouble();
                if (rangeCheck(s)) {
                    setStraighten(s);
5
CodeRank
This code example shows how to use the following methods:beginObject, endObject, name
        return new RectF(sNilRect);
    } 
 
    @Override 
    public void serializeRepresentation(JsonWriter writer) throws IOException {
        writer.beginObject();
        writer.name(BOUNDS[0]).value(mCrop.left);
        writer.name(BOUNDS[1]).value(mCrop.top);
        writer.name(BOUNDS[2]).value(mCrop.right);
        writer.name(BOUNDS[3]).value(mCrop.bottom);
        writer.endObject();
    } 
 
    @Override 
    public void deSerializeRepresentation(JsonReader reader) throws IOException {
        reader.beginObject();
        while (reader.hasNext()) {
            String name = reader.nextName();
            if (BOUNDS[0].equals(name)) {
                mCrop.left = (float) reader.nextDouble();
5
CodeRank
This code example shows how to use the following methods:beginArray, close, endArray
                    if (mHasWrittenData) {
                        // TODO: This is necessary to avoid an exception.  Better would be to not 
                        // even open the JsonWriter if the file is not even opened unless there is 
                        // valid data to write. 
                        if (!mHasWrittenData) {
                            mJsonWriter.beginArray();
                        } 
                        mJsonWriter.endArray();
                        mJsonWriter.close();
                        mHasWrittenData = false;
                    } 
                } finally { 
                    if (mFile != null) {
                        mFile.delete();
                    } 
                    if (onAbort != null) {
                        onAbort.run();
                    } 
                } 
                return null; 
5
CodeRank
This code example shows how to use the following methods:close
		dummy1.setFeatureName("Dummy Address");
		dummy1.setLatitude(30.12345);
		dummy1.setLongitude(-97.12345);
		 
		Bundle extras = new Bundle();
		extras.putString("formatted_address", "Formatted, pretty Dummy Address");
		dummy1.setExtras(extras);
		 
		Address dummy2 = new Address(Locale.getDefault());
		dummy2.setFeatureName("Dummy Address TWO");
		dummy2.setLatitude(31.54321);
		dummy2.setLongitude(-98.54321);
		 
		Bundle extras2 = new Bundle();
		extras2.putString("formatted_address", "Another pretty Dummy Address");
		dummy2.setExtras(extras2);
		 
		List<Address> addresses = new ArrayList<Address>();
		addresses.add(dummy1);
		addresses.add(dummy2);
5
CodeRank
This code example shows how to use the following methods:beginArray
        if (mFile == null) throw new FileNotFoundException();
        try { 
            final JsonWriter jsonWriter = createJsonWriter(mContext, mFile);
            if (jsonWriter == null) throw new IOException("Could not create JsonWriter");
 
            jsonWriter.beginArray();
            mJsonWriter = jsonWriter;
            mHasWrittenData = true;
            return mJsonWriter;
        } catch (final IOException e) {
            if (DEBUG) {
                Log.w(TAG, "Exception when creating JsonWriter", e);
                Log.w(TAG, "Closing JsonWriter");
            } 
            if (mJsonWriter != null) mJsonWriter.close();
            mJsonWriter = null;
            throw e;
        } 
    } 
 

4
CodeRank
This code example shows how to use the following methods:close
	} 
	 
	 
	public static String writeAddressToJson(Address address) {
		StringWriter sWriter = new StringWriter();
		JsonWriter jWriter = new JsonWriter(sWriter);
		 
		writeAddress(jWriter, address);
		 
		String output = sWriter.toString();
		 
		try { 
			jWriter.close();
			sWriter.close();
		} catch (IOException e) {
			Log.e(TAG, "IOException closing writer(s)");
		} 
		 
		return output;
	} 
4
CodeRank
This code example shows how to use the following methods:beginObject, endObject, name
	public int pxWidth;
	private int charsInWord;
 
	@Override 
	public void toJSON(JsonWriter out) throws IOException {
		out.beginObject();
		out.name("word_index").value(wordIndex + 1);
		out.name("word_index_delta").value(wordIndexDelta);
		out.name("relative_position").value(relativePosition);
		out.name("word").value(word);
		out.name("chars_in_word").value(word.length());
		out.name("pixels_in_word").value(pxWidth);
		out.name("event_time").value(time);
		out.name("time_since_last_event").value(tDelta);
		out.name("time_spent_on_word").value(timeSpent);
		out.endObject();
	} 
 
	public static void printHeaders(PrintWriter w) {
		w.print("word_index");
		w.print(",");
4
CodeRank

Related Android JsonWriter Questions & Answers:

See Code Examples for Android JsonWriter Methods: