當前位置: 首頁>>代碼示例>>Java>>正文


Java JsonWriter類代碼示例

本文整理匯總了Java中android.util.JsonWriter的典型用法代碼示例。如果您正苦於以下問題:Java JsonWriter類的具體用法?Java JsonWriter怎麽用?Java JsonWriter使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


JsonWriter類屬於android.util包,在下文中一共展示了JsonWriter類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: writeActions

import android.util.JsonWriter; //導入依賴的package包/類
@TargetApi(Build.VERSION_CODES.KITKAT)
private void writeActions(JsonWriter writer, Notification notification) throws IOException {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) {
        return;
    }

    if (notification.actions != null) {
        Log.d(TAG, "writing action");
        writer.name("actions");
        writer.beginArray();
        for (Notification.Action a : notification.actions) {
            Log.d(TAG, "writing action : " + a.title.toString());
            writer.beginObject();
            writer.name("title").value(a.title.toString());
            writer.endObject();
        }
        writer.endArray();
    }
}
 
開發者ID:RomascuAndrei,項目名稱:BTNotifierAndroid,代碼行數:20,代碼來源:Message.java

示例2: prepareJSRuntime

import android.util.JsonWriter; //導入依賴的package包/類
public void prepareJSRuntime(JSDebuggerCallback callback) {
  int requestID = mRequestID.getAndIncrement();
  mCallbacks.put(requestID, callback);

  try {
    StringWriter sw = new StringWriter();
    JsonWriter js = new JsonWriter(sw);
    js.beginObject()
      .name("id").value(requestID)
      .name("method").value("prepareJSRuntime")
      .endObject()
      .close();
    sendMessage(requestID, sw.toString());
  } catch (IOException e) {
    triggerRequestFailure(requestID, e);
  }
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:18,代碼來源:JSDebuggerWebSocketClient.java

示例3: loadApplicationScript

import android.util.JsonWriter; //導入依賴的package包/類
public void loadApplicationScript(
    String sourceURL,
    HashMap<String, String> injectedObjects,
    JSDebuggerCallback callback) {
  int requestID = mRequestID.getAndIncrement();
  mCallbacks.put(requestID, callback);

  try {
    StringWriter sw = new StringWriter();
    JsonWriter js = new JsonWriter(sw)
       .beginObject()
       .name("id").value(requestID)
       .name("method").value("executeApplicationScript")
       .name("url").value(sourceURL)
       .name("inject").beginObject();
    for (String key : injectedObjects.keySet()) {
      js.name(key).value(injectedObjects.get(key));
    }
    js.endObject().endObject().close();
    sendMessage(requestID, sw.toString());
  } catch (IOException e) {
    triggerRequestFailure(requestID, e);
  }
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:25,代碼來源:JSDebuggerWebSocketClient.java

示例4: executeJSCall

import android.util.JsonWriter; //導入依賴的package包/類
public void executeJSCall(
    String methodName,
    String jsonArgsArray,
    JSDebuggerCallback callback) {
  int requestID = mRequestID.getAndIncrement();
  mCallbacks.put(requestID, callback);

  try {
    StringWriter sw = new StringWriter();
    JsonWriter js = new JsonWriter(sw);

    js.beginObject()
      .name("id").value(requestID)
      .name("method").value(methodName);
    /* JsonWriter does not offer writing raw string (without quotes), that's why
       here we directly write to output string using the the underlying StringWriter */
    sw.append(",\"arguments\":").append(jsonArgsArray);
    js.endObject().close();
    sendMessage(requestID, sw.toString());
  } catch (IOException e) {
    triggerRequestFailure(requestID, e);
  }
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:24,代碼來源:JSDebuggerWebSocketClient.java

示例5: listToJsonStr

import android.util.JsonWriter; //導入依賴的package包/類
public static String listToJsonStr(final List<Object> list) {
    if (list == null || list.isEmpty()) {
        return EMPTY_STRING;
    }
    final StringWriter sw = new StringWriter();
    final JsonWriter writer = new JsonWriter(sw);
    try {
        writer.beginArray();
        for (final Object o : list) {
            writer.beginObject();
            if (o instanceof Integer) {
                writer.name(INTEGER_CLASS_NAME).value((Integer)o);
            } else if (o instanceof String) {
                writer.name(STRING_CLASS_NAME).value((String)o);
            }
            writer.endObject();
        }
        writer.endArray();
        return sw.toString();
    } catch (final IOException e) {
    } finally {
        close(writer);
    }
    return EMPTY_STRING;
}
 
開發者ID:sergeychilingaryan,項目名稱:AOSP-Kayboard-7.1.2,代碼行數:26,代碼來源:JsonUtils.java

示例6: encode

import android.util.JsonWriter; //導入依賴的package包/類
private static String encode(String uri, ShareTuple tuple) {
  final StringWriter stringWriter = new StringWriter();
  try (final JsonWriter jsonWriter = new JsonWriter(stringWriter)) {
    jsonWriter.beginObject();
    jsonWriter.name(URI_KEY).value(uri);

    jsonWriter.name(CREDENTIAL_TUPLE_KEY);
    encodeTuple(jsonWriter, tuple);
    jsonWriter.endObject();
  } catch (IOException e) {
    Log.e(TAG, "Failed to encode credential for " + uri);
    return null;
  }

  return stringWriter.toString();
}
 
開發者ID:google,項目名稱:samba-documents-provider,代碼行數:17,代碼來源:ShareManager.java

示例7: onOpen

import android.util.JsonWriter; //導入依賴的package包/類
@Override
public void onOpen(ServerHandshake handshakedata) {

    StringWriter stringWriter = new StringWriter();
    JsonWriter writer = new JsonWriter(stringWriter);

    try {
        writer.beginObject();
        writer.name("event").value("onOpen");
        writer.name("resourceId").value(this.id);
        writer.endObject();
    } catch (IOException e) {
        e.printStackTrace();
    }

    this.callback(PluginResult.Status.OK, stringWriter.toString());
}
 
開發者ID:flynetworks,項目名稱:cordova-websocket-clientcert,代碼行數:18,代碼來源:WebSocketClient.java

示例8: onMessage

import android.util.JsonWriter; //導入依賴的package包/類
@Override
public void onMessage(String message) {

    StringWriter stringWriter = new StringWriter();
    JsonWriter writer = new JsonWriter(stringWriter);

    try {
        writer.beginObject();
        writer.name("event").value("onMessage");
        writer.name("message").value(message);
        writer.endObject();
    } catch (IOException e) {
        e.printStackTrace();
    }

    this.callback(PluginResult.Status.OK, stringWriter.toString());
}
 
開發者ID:flynetworks,項目名稱:cordova-websocket-clientcert,代碼行數:18,代碼來源:WebSocketClient.java

示例9: onClose

import android.util.JsonWriter; //導入依賴的package包/類
@Override
public void onClose(int code, String reason, boolean remote) {
    StringWriter stringWriter = new StringWriter();
    JsonWriter writer = new JsonWriter(stringWriter);

    try {
        writer.beginObject();
        writer.name("event").value("onClose");
        writer.name("code").value(code);
        writer.name("reason").value(reason);
        writer.name("remote").value(remote);
        writer.endObject();
    } catch (IOException e) {
        e.printStackTrace();
    }

    this.callback(PluginResult.Status.OK, stringWriter.toString());
}
 
開發者ID:flynetworks,項目名稱:cordova-websocket-clientcert,代碼行數:19,代碼來源:WebSocketClient.java

示例10: onError

import android.util.JsonWriter; //導入依賴的package包/類
@Override
public void onError(Exception ex) {
    StringWriter stringWriter = new StringWriter();
    JsonWriter writer = new JsonWriter(stringWriter);

    try {
        writer.beginObject();
        writer.name("event").value("onError");

        if (ex instanceof UnresolvedAddressException) {
            writer.name("errorCode").value("ERR_NAME_NOT_RESOLVED");
            writer.name("errorMessage").value("Unable to resolve address. Please check the url and your network connection");
        } else {
            writer.name("errorCode").value("ERR_NAME_UNKNOWN");
            writer.name("errorMessage").value("Unknown error was thrown");
        }

        writer.endObject();
    } catch (IOException e) {
        e.printStackTrace();
    }

    this.callback(PluginResult.Status.OK, stringWriter.toString());
}
 
開發者ID:flynetworks,項目名稱:cordova-websocket-clientcert,代碼行數:25,代碼來源:WebSocketClient.java

示例11: writeValue

import android.util.JsonWriter; //導入依賴的package包/類
/**
 * Writes the given {@link Object} to the {@link JsonWriter}.
 *
 * @throws IOException
 */
private static void writeValue(Object value, JsonWriter writer) throws IOException {
  if (value == null) {
    writer.nullValue();
  } else if (value instanceof Number) {
    writer.value((Number) value);
  } else if (value instanceof Boolean) {
    writer.value((Boolean) value);
  } else if (value instanceof List) {
    listToWriter((List) value, writer);
  } else if (value instanceof Map) {
    mapToWriter((Map) value, writer);
  } else {
    writer.value(String.valueOf(value));
  }
}
 
開發者ID:f2prateek,項目名稱:segment-android,代碼行數:21,代碼來源:JsonUtils.java

示例12: writeSettings

import android.util.JsonWriter; //導入依賴的package包/類
private void writeSettings(@NonNull final JsonWriter writer) throws IOException {
    // Write settings
    writer.name("Settings").beginObject();

    if (mSharedPreferences.contains(KEY_GENERAL_CLOCK_MODE_STRING)) {
        writer.name(KEY_GENERAL_CLOCK_MODE_STRING)
                .value(mSharedPreferences.getString(KEY_GENERAL_CLOCK_MODE_STRING, "-1"));
    }

    if (mSharedPreferences.contains(KEY_NOTIFICATIONS_ACTIVE_BOOL)) {
        writer.name(KEY_NOTIFICATIONS_ACTIVE_BOOL)
                .value(mSharedPreferences.getBoolean(KEY_NOTIFICATIONS_ACTIVE_BOOL, true));
    }

    if (mSharedPreferences.contains(KEY_NOTIFICATIONS_DAILY_REMAINDER_BOOL)) {
        writer.name(KEY_NOTIFICATIONS_DAILY_REMAINDER_BOOL)
                .value(mSharedPreferences.getBoolean(KEY_NOTIFICATIONS_DAILY_REMAINDER_BOOL, true));
    }

    if (mSharedPreferences.contains(KEY_NOTIFICATIONS_DAILY_REMAINDER_TIME_STRING)) {
        writer.name(KEY_NOTIFICATIONS_DAILY_REMAINDER_TIME_STRING)
                .value(mSharedPreferences.getString(KEY_NOTIFICATIONS_DAILY_REMAINDER_TIME_STRING, "19:00"));
    }

    writer.endObject();
}
 
開發者ID:canyapan,項目名稱:DietDiaryApp,代碼行數:27,代碼來源:DriveBackupService.java

示例13: writeEvent

import android.util.JsonWriter; //導入依賴的package包/類
private void writeEvent(@NonNull final JsonWriter writer, @NonNull final String[] types,
                        @NonNull final String[] foodTypes, @NonNull final String[] drinkTypes,
                        @NonNull Event event) throws IOException {
    String subType;
    switch (event.getType()) {
        case Event.TYPE_FOOD:
            subType = foodTypes[event.getSubType()];
            break;
        case Event.TYPE_DRINK:
            subType = drinkTypes[event.getSubType()];
            break;
        default:
            subType = "";
    }

    writer.beginObject();
    writer.name(KEY_ID).value(event.getID());
    writer.name(KEY_DATE).value(event.getDate().toString(DatabaseHelper.DB_DATE_FORMATTER));
    writer.name(KEY_TIME).value(event.getTime().toString(DatabaseHelper.DB_TIME_FORMATTER));
    writer.name(KEY_TYPE).value(types[event.getType()]);
    writer.name(KEY_TITLE).value(subType);
    writer.name(KEY_DESC).value(event.getDescription());
    writer.endObject();
}
 
開發者ID:canyapan,項目名稱:DietDiaryApp,代碼行數:25,代碼來源:DriveBackupService.java

示例14: toJson

import android.util.JsonWriter; //導入依賴的package包/類
public String toJson() {
    final StringWriter sw = new StringWriter(256);
    final JsonWriter writer = new JsonWriter(sw);

    try {
        writer.beginObject()
                .name("uuid").value(uuid)
                .name("ucode").value(ucode)
                .name("session").value(session)
                .endObject()
                .close();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }

    return sw.toString();
}
 
開發者ID:CzBiX,項目名稱:peanut-link,代碼行數:18,代碼來源:User.java

示例15: a

import android.util.JsonWriter; //導入依賴的package包/類
public final byte[] a(T paramT)
{
  ByteArrayOutputStream localByteArrayOutputStream = new ByteArrayOutputStream();
  String str1;
  try
  {
    JsonWriter localJsonWriter = new JsonWriter(new BufferedWriter(new OutputStreamWriter(localByteArrayOutputStream, e), 8192));
    a(localJsonWriter, paramT);
    localJsonWriter.flush();
    return localByteArrayOutputStream.toByteArray();
  }
  catch (IOException localIOException)
  {
    str1 = String.valueOf(getClass().getSimpleName());
    if (str1.length() == 0) {}
  }
  for (String str2 = "Cannot generate JSON using ".concat(str1);; str2 = new String("Cannot generate JSON using ")) {
    throw new RuntimeException(str2, localIOException);
  }
}
 
開發者ID:ChiangC,項目名稱:FMTech,代碼行數:21,代碼來源:csf.java


注:本文中的android.util.JsonWriter類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。