本文整理汇总了Java中android.util.JsonToken.NULL属性的典型用法代码示例。如果您正苦于以下问题:Java JsonToken.NULL属性的具体用法?Java JsonToken.NULL怎么用?Java JsonToken.NULL使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.util.JsonToken
的用法示例。
在下文中一共展示了JsonToken.NULL属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: deserializeStringCollection
/**
* A generic deserializer for string collections.
*
* @param serialized JSON representation of a string collection.
* @param collectionClass Concrete, instantiatable collection class, e.g. {@code ArrayList.class}.
* @param <C> A concrete collection class, e.g. {@code ArrayList<String>}.
* @return A collection instance retrieved from {@code serialized}.
*/
@NonNull
public static <C extends Collection<String>> C deserializeStringCollection(@NonNull String serialized,
@NonNull Class<?> collectionClass) {
C collection = createCollection(collectionClass);
StringReader reader = new StringReader(serialized);
JsonReader jsonReader = new JsonReader(reader);
try {
jsonReader.beginArray();
while (jsonReader.hasNext()) {
if (jsonReader.peek() == JsonToken.NULL) {
jsonReader.nextNull();
collection.add(null);
} else {
collection.add(jsonReader.nextString());
}
}
jsonReader.endArray();
jsonReader.close();
return collection;
} catch (IOException e) {
return collection;
}
}
示例2: insertJournal
private void insertJournal(JsonReader jsonReader, Journal journal) throws IOException {
jsonReader.beginObject();
while (jsonReader.hasNext()) {
String key = jsonReader.nextName();
if(jsonReader.peek() == JsonToken.NULL) continue;
if (key.equals(KEY_ID)) journal.setId(jsonReader.nextLong());
else if (key.equals(KEY_DATE)) journal.setDate(jsonReader.nextLong());
else if (key.equals(KEY_NOTE)) journal.setNote(jsonReader.nextString());
else if (key.equals(KEY_AMOUNT)) journal.setAmount(jsonReader.nextDouble());
else if (key.equals(KEY_CREATED_DATE)) journal.setCreatedDate(jsonReader.nextLong());
else if (key.equals(KEY_TYPE)) journal.setType(Journal.Type.valueOf(jsonReader.nextString()));
else if (key.equals(KEY_ATTACHMENTS)) {
//this logic assumes that key_attachments comes at the end
long newId = mServices.addJournal(journal);
insertAttachmentsIntoDB(jsonReader, newId);
}
else jsonReader.skipValue();
}
jsonReader.endObject();
}
示例3: insertAttachment
private void insertAttachment(JsonReader jsonReader, Attachment attachment) throws IOException {
if(jsonReader.peek() == JsonToken.NAME) {
jsonReader.beginObject();
while (jsonReader.hasNext()) {
String key = jsonReader.nextName();
if (jsonReader.peek() == JsonToken.NULL) continue;
if (key.equals(KEY_ID)) attachment.setId(jsonReader.nextLong());
else if (key.equals(KEY_PATH)) attachment.setPath(jsonReader.nextString());
else jsonReader.skipValue();
}
mServices.addAttachment(attachment);
jsonReader.endObject();
}else{
//for old json format
while (jsonReader.hasNext()) {
if (jsonReader.peek() == JsonToken.NULL) continue;
else attachment.setPath(jsonReader.nextString());
}
mServices.addAttachment(attachment);
}
}
示例4: readNGWFeatureAttachments
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static void readNGWFeatureAttachments(Feature feature, JsonReader reader)
throws IOException
{
//add extensions
reader.beginObject();
while (reader.hasNext()) {
String name = reader.nextName();
if (name.equals("attachment") && reader.peek() != JsonToken.NULL) {
reader.beginArray();
while (reader.hasNext()) {
readNGWFeatureAttachment(feature, reader);
}
reader.endArray();
} else {
reader.skipValue();
}
}
reader.endObject();
}
示例5: createUsingJsonStream
@SuppressWarnings("cast")
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static some.test.Simple createUsingJsonStream(Realm realm, JsonReader reader)
throws IOException {
final some.test.Simple obj = new some.test.Simple();
final SimpleRealmProxyInterface objProxy = (SimpleRealmProxyInterface) obj;
reader.beginObject();
while (reader.hasNext()) {
String name = reader.nextName();
if (false) {
} else if (name.equals("name")) {
if (reader.peek() != JsonToken.NULL) {
objProxy.realmSet$name((String) reader.nextString());
} else {
reader.skipValue();
objProxy.realmSet$name(null);
}
} else if (name.equals("age")) {
if (reader.peek() != JsonToken.NULL) {
objProxy.realmSet$age((int) reader.nextInt());
} else {
reader.skipValue();
throw new IllegalArgumentException("Trying to set non-nullable field 'age' to null.");
}
} else {
reader.skipValue();
}
}
reader.endObject();
return realm.copyToRealm(obj);
}
示例6: readParentComment
private ParentComment readParentComment() throws IOException {
String content = null;
String author = null;
String link = null;
reader.beginObject();
while (reader.hasNext()) {
String name = reader.nextName();
JsonToken check = reader.peek();
if (check == JsonToken.NULL) {
reader.skipValue();
continue;
}
switch (name) {
case "author":
author = formatUsername(reader.nextString());
break;
case "orig_body":
content = reader.nextString().replace("^", "");
break;
case "link":
link = reader.nextString();
break;
default:
reader.skipValue();
break;
}
}
reader.endObject();
return new ParentComment(content, author, link);
}
示例7: readString
@Override
public String readString() throws IOException {
mReader.nextName();
if (mReader.peek() == JsonToken.NULL) {
mReader.nextNull();
return null;
}
return mReader.nextString();
}
示例8: readImageUri
private void readImageUri(JsonReader reader) throws IOException {
reader.nextName();
if (reader.peek() == JsonToken.NULL) {
reader.nextNull();
mImageUri = null;
} else
mImageUri = reader.nextString();
}
示例9: hasNextSkipNull
protected static boolean hasNextSkipNull(JsonReader reader) throws IOException {
while (reader.hasNext()) {
if (reader.peek() == JsonToken.NULL) {
reader.skipValue();
} else {
return true;
}
}
return false;
}
示例10: getNextNotNullName
protected static final String getNextNotNullName(JsonReader reader) throws IOException {
while (reader.hasNext()) {
String name = reader.nextName();
JsonToken jsonToken = reader.peek();
if (jsonToken != JsonToken.NULL) {
return name;
}
reader.skipValue();
}
return null;
}
示例11: decodeTuple
private static ShareTuple decodeTuple(JsonReader reader) throws IOException {
if (reader.peek() == JsonToken.NULL) {
reader.nextNull();
return ShareTuple.EMPTY_TUPLE;
}
String workgroup = null;
String username = null;
String password = null;
boolean mounted = true;
reader.beginObject();
while (reader.hasNext()) {
String name = reader.nextName();
switch (name) {
case WORKGROUP_KEY:
workgroup = reader.nextString();
break;
case USERNAME_KEY:
username = reader.nextString();
break;
case PASSWORD_KEY:
password = reader.nextString();
break;
case MOUNT_KEY:
mounted = reader.nextBoolean();
default:
Log.w(TAG, "Ignoring unknown key " + name);
}
}
reader.endObject();
return new ShareTuple(workgroup, username, password, mounted);
}
示例12: insertParty
/**
* Inserts a Party and it's Journals and attachments into the database
* @param jsonReader
* @param newParty
* @throws IOException
*/
private void insertParty(JsonReader jsonReader, Party newParty) throws IOException {
//consume open curly braces {
jsonReader.beginObject();
//loop through keys/names which represents variable
while (jsonReader.hasNext()) {
String key = jsonReader.nextName();
//if the value is null, continue to next key
if (jsonReader.peek() == JsonToken.NULL) continue;
if (key.equals(KEY_ID)) newParty.setId(jsonReader.nextLong());
else if (key.equals(KEY_TYPE)) newParty.setType(Party.Type.valueOf(jsonReader.nextString()));
else if (key.equals(KEY_NAME)) newParty.setName(jsonReader.nextString());
else if (key.equals(KEY_PHONE)) newParty.setPhone(jsonReader.nextString());
//Debit and Credit balance will be calculated as Journals are added
//else if (key.equals(KEY_DEBIT)) newParty.setDebitTotal(jsonReader.nextDouble());
//else if (key.equals(KEY_CREDIT)) newParty.setCreditTotal(jsonReader.nextDouble());
else if (key.equals(KEY_PICTURE)) newParty.setPicturePath(jsonReader.nextString());
else if (key.equals(KEY_JOURNALS)) {
//this logic assumes that KEY_JOURNALS comes at the end
long id = mServices.addParty(newParty);
Log.d(TAG, newParty.getName() + " created");
insertJournalsIntoDb(jsonReader, id);
} else jsonReader.skipValue(); //skip unknown key
}
//consume close curly braces }
jsonReader.endObject();
}
示例13: handleNull
/**
* If the next value is {@link JsonToken#NULL}, consume it and return {@code true}. Otherwise
* return {@code false}.
*/
public static boolean handleNull(JsonReader reader) throws IOException {
if (reader.peek() == JsonToken.NULL) {
reader.nextNull();
return true;
}
return false;
}
示例14: readNGWFeature
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
public static Feature readNGWFeature(
JsonReader reader,
List<Field> fields,
int nSRS)
throws IOException, IllegalStateException, NumberFormatException, OutOfMemoryError
{
final Feature feature = new Feature(Constants.NOT_FOUND, fields);
reader.beginObject();
while (reader.hasNext()) {
String name = reader.nextName();
if (name.equals(NGWUtil.NGWKEY_ID)) {
feature.setId(reader.nextLong());
} else if (name.equals(NGWUtil.NGWKEY_GEOM)) {
String wkt = reader.nextString();
GeoGeometry geom = GeoGeometryFactory.fromWKT(wkt, nSRS);
geom.setCRS(nSRS);
if (nSRS != GeoConstants.CRS_WEB_MERCATOR) {
geom.project(GeoConstants.CRS_WEB_MERCATOR);
}
feature.setGeometry(geom);
} else if (name.equals(NGWUtil.NGWKEY_FIELDS)) {
readNGWFeatureFields(feature, reader, fields);
} else if (name.equals(NGWUtil.NGWKEY_EXTENSIONS)) {
if (reader.peek() != JsonToken.NULL) {
readNGWFeatureAttachments(feature, reader);
}
} else {
reader.skipValue();
}
}
reader.endObject();
return feature;
}
示例15: readNGWFeatureAttachment
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
private static void readNGWFeatureAttachment(Feature feature, JsonReader reader)
throws IOException
{
reader.beginObject();
String attachId = "";
String name = "";
String mime = "";
String descriptionText = "";
while (reader.hasNext()) {
String keyName = reader.nextName();
if (reader.peek() == JsonToken.NULL) {
reader.skipValue();
continue;
}
if (keyName.equals(NGWUtil.NGWKEY_ID)) {
attachId += reader.nextLong();
} else if (keyName.equals(NGWUtil.NGWKEY_NAME)) {
name += reader.nextString();
} else if (keyName.equals(NGWUtil.NGWKEY_MIME)) {
mime += reader.nextString();
} else if (keyName.equals(NGWUtil.NGWKEY_DESCRIPTION)) {
descriptionText += reader.nextString();
} else {
reader.skipValue();
}
}
AttachItem item = new AttachItem(attachId, name, mime, descriptionText);
feature.addAttachment(item);
reader.endObject();
}