本文整理匯總了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();
}
}
示例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);
}
}
示例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);
}
}
示例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);
}
}
示例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;
}
示例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();
}
示例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());
}
示例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());
}
示例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());
}
示例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());
}
示例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));
}
}
示例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();
}
示例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();
}
示例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();
}
示例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);
}
}