Java Code Examples for android.util.JsonToken#NULL

The following examples show how to use android.util.JsonToken#NULL . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BundleDeltaClient.java    From react-native-GPay with MIT License 6 votes vote down vote up
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;
}
 
Example 2
Source File: NGWUtil.java    From android_maplib with GNU Lesser General Public License v3.0 6 votes vote down vote up
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();
}
 
Example 3
Source File: GalleryData.java    From NClientV2 with Apache License 2.0 5 votes vote down vote up
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();
}
 
Example 4
Source File: JSDebuggerWebSocketClient.java    From react-native-GPay with MIT License 5 votes vote down vote up
@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);
    }
  }
}
 
Example 5
Source File: ShareManager.java    From samba-documents-provider with GNU General Public License v3.0 5 votes vote down vote up
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);
}
 
Example 6
Source File: NGWUtil.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
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;
}
 
Example 7
Source File: NGWUtil.java    From android_maplib with GNU Lesser General Public License v3.0 5 votes vote down vote up
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();
}
 
Example 8
Source File: BatchManagerTest.java    From background-geolocation-android with Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 9
Source File: NGWUtil.java    From android_maplib with GNU Lesser General Public License v3.0 4 votes vote down vote up
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();
}