下面列出了android.util.JsonToken#NULL 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private static int patchDelta(JsonReader jsonReader, LinkedHashMap<Number, byte[]> map)
throws IOException {
jsonReader.beginArray();
int numModules = 0;
while (jsonReader.hasNext()) {
jsonReader.beginArray();
int moduleId = jsonReader.nextInt();
if (jsonReader.peek() == JsonToken.NULL) {
jsonReader.skipValue();
map.remove(moduleId);
} else {
map.put(moduleId, jsonReader.nextString().getBytes());
}
jsonReader.endArray();
numModules++;
}
jsonReader.endArray();
return numModules;
}
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();
}
private void readTitles(JsonReader jr) throws IOException {
jr.beginObject();
while(jr.peek()!=JsonToken.END_OBJECT){
switch (jr.nextName()){
case "japanese":setTitle(TitleType.JAPANESE,jr.peek()!=JsonToken.NULL?jr.nextString():"");break;
case "english": setTitle(TitleType.ENGLISH ,jr.peek()!=JsonToken.NULL?jr.nextString():"");break;
case "pretty": setTitle(TitleType.PRETTY ,jr.peek()!=JsonToken.NULL?jr.nextString():"");break;
default:jr.skipValue();break;
}
if(jr.peek()==JsonToken.NULL)jr.skipValue();
}
jr.endObject();
}
@Override
public void onMessage(WebSocket webSocket, String text) {
Integer replyID = null;
try {
JsonReader reader = new JsonReader(new StringReader(text));
String result = null;
reader.beginObject();
while (reader.hasNext()) {
String field = reader.nextName();
if (JsonToken.NULL == reader.peek()) {
reader.skipValue();
continue;
}
if ("replyID".equals(field)) {
replyID = reader.nextInt();
} else if ("result".equals(field)) {
result = reader.nextString();
} else if ("error".equals(field)) {
String error = reader.nextString();
abort(error, new JavascriptException(error));
}
}
if (replyID != null) {
triggerRequestSuccess(replyID, result);
}
} catch (IOException e) {
if (replyID != null) {
triggerRequestFailure(replyID, e);
} else {
abort("Parsing response message from websocket failed", e);
}
}
}
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);
}
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;
}
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();
}
private List<BackgroundLocation> readLocationsArray(JsonReader reader) throws IOException {
List<BackgroundLocation> locations = new ArrayList<BackgroundLocation>();
reader.beginArray();
while (reader.hasNext()) {
BackgroundLocation l = new BackgroundLocation();
reader.beginObject();
while (reader.hasNext()) {
String name = reader.nextName();
if (name.equals("id")) {
l.setLocationId(reader.nextLong());
} else if (name.equals("time")) {
l.setTime(reader.nextLong());
} else if (name.equals("latitude")) {
l.setLatitude(reader.nextDouble());
} else if (name.equals("longitude")) {
l.setLongitude(reader.nextDouble());
} else if (name.equals("accuracy")) {
l.setAccuracy((float)reader.nextDouble());
} else if (name.equals("speed")) {
l.setSpeed((float)reader.nextDouble());
} else if (name.equals("bearing")) {
l.setBearing((float)reader.nextDouble());
} else if (name.equals("altitude")) {
l.setAltitude(reader.nextDouble());
} else if (name.equals("radius")) {
JsonToken token = reader.peek();
if (token != JsonToken.NULL) {
l.setRadius((float)reader.nextDouble());
} else {
reader.skipValue();
}
} else if (name.equals("provider")) {
l.setProvider(reader.nextString());
} else if (name.equals("locationProvider")) {
l.setLocationProvider(reader.nextInt());
} else {
reader.skipValue();
}
}
reader.endObject();
locations.add(l);
}
reader.endArray();
return locations;
}
public static void readNGWFeatureFields(Feature feature, JsonReader reader, List<Field> fields)
throws IOException, IllegalStateException, NumberFormatException
{
reader.beginObject();
while (reader.hasNext()) {
String name = reader.nextName();
if (reader.peek() == JsonToken.NULL) {
reader.skipValue();
} else {
boolean bAdded = false;
for (Field field : fields) {
if (field.getName().equals(name) || field.getName().equals(LayerUtil.normalizeFieldName(name))) {
switch (field.getType()) {
case GeoConstants.FTReal:
feature.setFieldValue(field.getName(), reader.nextDouble());
bAdded = true;
break;
case GeoConstants.FTInteger:
feature.setFieldValue(field.getName(), reader.nextInt());
bAdded = true;
break;
case GeoConstants.FTString:
feature.setFieldValue(field.getName(), reader.nextString());
bAdded = true;
break;
case GeoConstants.FTDate:
case GeoConstants.FTTime:
case GeoConstants.FTDateTime:
readNGWDate(feature, reader, field.getName());
bAdded = true;
break;
default:
break;
}
break;
}
}
if (!bAdded) {
reader.skipValue();
}
}
}
reader.endObject();
}