Java Code Examples for android.util.JsonReader#nextLong()

The following examples show how to use android.util.JsonReader#nextLong() . 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: GalleryData.java    From NClientV2 with Apache License 2.0 6 votes vote down vote up
private void parseJSON(JsonReader jr) throws IOException {
    jr.beginObject();
    while(jr.peek()!= JsonToken.END_OBJECT){
        switch(jr.nextName()){
            case "upload_date":uploadDate=new Date(jr.nextLong()*1000);break;
            case "num_favorites":favoriteCount=jr.nextInt();break;
            case "media_id":mediaId=jr.nextInt();break;
            case "title":readTitles(jr);break;
            case "images":readImages(jr); break;
            case "tags":readTags(jr);break;
            case "id":id=jr.nextInt();break;
            case "num_pages":pageCount=jr.nextInt();break;
            case "error":jr.skipValue(); valid=false;break;
            default:jr.skipValue();break;
        }
    }
    jr.endObject();
}
 
Example 2
Source File: Comment.java    From NClientV2 with Apache License 2.0 5 votes vote down vote up
public Comment(JsonReader reader) throws IOException {
    reader.beginObject();
    while(reader.peek()!= JsonToken.END_OBJECT){
        switch (reader.nextName()){
            case "id":id=reader.nextInt();break;
            case "post_date":postDate=new Date(reader.nextLong()*1000);break;
            case "body":body=reader.nextString();break;
            case "poster":poster=new User(reader);break;
            default:reader.skipValue();break;
        }
    }
    reader.endObject();
}
 
Example 3
Source File: JSONParser.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
private static ZCashTransactionInput readTxSingleInput(JsonReader reader) throws IOException {
  ZCashTransactionInput input = new ZCashTransactionInput();
  reader.beginObject();
  while (reader.peek() != JsonToken.END_OBJECT) {
    String name = reader.nextName();
    switch (name) {
      case COINBASE:
        input.coinbase = reader.nextString();
        break;
      case SEQUENCE:
        input.sequence = reader.nextLong();
        break;
      case TXID:
        input.txid = reader.nextString();
        break;
      case VOUT:
        input.n = reader.nextLong();
        break;
      case SCRIPTSIG:
        reader.skipValue();
        break;
      case RETRIEVEDVOUT:
        input.copyDataFrom(readTxSingleOutput(reader));
        break;
      default:
        reader.skipValue();
    }
  }

  reader.endObject();
  return input;
}
 
Example 4
Source File: JSONParser.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
private static long readFieldLong(JsonReader reader, boolean fromDouble) throws IOException {
  reader.nextName();
  if (fromDouble) {
    return Double.valueOf(reader.nextDouble() * 1e8).longValue();
  }

  return reader.nextLong();
}
 
Example 5
Source File: JSONParser.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
private static ZCashTransactionInput readTxSingleInput(JsonReader reader) throws IOException {
  ZCashTransactionInput input = new ZCashTransactionInput();
  reader.beginObject();
  while (reader.peek() != JsonToken.END_OBJECT) {
    String name = reader.nextName();
    switch (name) {
      case COINBASE:
        input.coinbase = reader.nextString();
        break;
      case SEQUENCE:
        input.sequence = reader.nextLong();
        break;
      case TXID:
        input.txid = reader.nextString();
        break;
      case VOUT:
        input.n = reader.nextLong();
        break;
      case SCRIPTSIG:
        reader.skipValue();
        break;
      case RETRIEVEDVOUT:
        input.copyDataFrom(readTxSingleOutput(reader));
        break;
      default:
        reader.skipValue();
    }
  }

  reader.endObject();
  return input;
}
 
Example 6
Source File: JSONParser.java    From guarda-android-wallets with GNU General Public License v3.0 5 votes vote down vote up
private static long readFieldLong(JsonReader reader, boolean fromDouble) throws IOException {
  reader.nextName();
  if (fromDouble) {
    return Double.valueOf(reader.nextDouble() * 1e8).longValue();
  }

  return reader.nextLong();
}
 
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: JSONParser.java    From guarda-android-wallets with GNU General Public License v3.0 4 votes vote down vote up
private static ZCashTransactionDetails_taddr readTx(JsonReader reader) throws IOException, IllegalStateException {
  ZCashTransactionDetails_taddr tx = new ZCashTransactionDetails_taddr();
  if(reader.peek() != JsonToken.BEGIN_OBJECT) {
    throw new IOException("Cannot parse JSON");
  }

  reader.beginObject();
  while (reader.peek() != JsonToken.END_OBJECT) {
    String name = reader.nextName();
    switch (name) {
      case HASH:
        tx.hash = reader.nextString();
        break;
      case MAINCHAIN:
        tx.mainChain = reader.nextBoolean();
        break;
      case FEE:
        tx.fee = Double.valueOf(reader.nextDouble() * 1e8).longValue();
        break;
      case TYPE:
        tx.type = reader.nextString();
        break;
      case SHIELDED:
        tx.shielded = reader.nextBoolean();
        break;
      case INDEX:
        tx.index = reader.nextLong();
        break;
      case BLOCKHASH:
        tx.blockHash = reader.nextString();
        break;
      case BLOCKHEIGHT:
        tx.blockHeight = reader.nextLong();
        break;
      case VERSION:
        tx.version = reader.nextLong();
        break;
      case LOCKTIME:
        tx.locktime = reader.nextLong();
        break;
      case TIME:
        tx.time = reader.nextLong();
        break;
      case TIMESTAMP:
        tx.timestamp = reader.nextLong();
        break;
      case VIN:
        tx.vin = readTxInputs(reader);
        break;
      case VOUT:
        tx.vout = readTxOutputs(reader, null);
        break;
      case VJOINSPLIT:
        skipJoinSplits(reader);
        break;
      case VALUE:
        tx.value = Double.valueOf(reader.nextDouble() * 1e8).longValue();
        break;
      case OUTPUTVALUE:
        tx.outputValue = Double.valueOf(reader.nextDouble() * 1e8).longValue();
        break;
      case SHIELDEDVALUE:
        tx.shieldedValue = Double.valueOf(reader.nextDouble() * 1e8).longValue();
        break;
      default:
        reader.skipValue();
    }
  }

  reader.endObject();
  return tx;
}
 
Example 9
Source File: JSONParser.java    From guarda-android-wallets with GNU General Public License v3.0 4 votes vote down vote up
private static ZCashTransactionOutput readTxSingleOutput(JsonReader reader) throws IOException {
  ZCashTransactionOutput output = new ZCashTransactionOutput();
  reader.beginObject(); //output
  while (reader.peek() != JsonToken.END_OBJECT) {
    String name = reader.nextName();
    switch (name) {
      case N:
        output.n = reader.nextLong();
        break;
      case SCRIPTPUBKEY:
        reader.beginObject();
        while (reader.peek() != JsonToken.END_OBJECT) {
          name = reader.nextName();
          switch (name) {
            case ADDRESSES:
              reader.beginArray();
              while (reader.hasNext()) {
                output.address = reader.nextString();
              }
              reader.endArray();
              break;
            case ASM:
              output.asm = reader.nextString();
              break;
            case HEX:
              output.hex = reader.nextString();
              break;
            case REQSIGS:
              output.regSigs = reader.nextLong();
              break;
            case TYPE:
              output.type = reader.nextString();
              break;
            default:
              reader.skipValue();
          }
        }
        reader.endObject();
        break;
      case VALUE:
        output.value = Double.valueOf(reader.nextDouble() * 1e8).longValue();
        break;
      case VALUEZAT:
        output.value = reader.nextLong();
        break;
      default:
        reader.skipValue();
    }
  }

  reader.endObject(); //output end
  return output;
}
 
Example 10
Source File: JSONParser.java    From guarda-android-wallets with GNU General Public License v3.0 4 votes vote down vote up
private static ZCashTransactionDetails_taddr readTx(JsonReader reader) throws IOException, IllegalStateException {
  ZCashTransactionDetails_taddr tx = new ZCashTransactionDetails_taddr();
  if(reader.peek() != JsonToken.BEGIN_OBJECT) {
    throw new IOException("Cannot parse JSON");
  }

  reader.beginObject();
  while (reader.peek() != JsonToken.END_OBJECT) {
    String name = reader.nextName();
    switch (name) {
      case HASH:
        tx.hash = reader.nextString();
        break;
      case MAINCHAIN:
        tx.mainChain = reader.nextBoolean();
        break;
      case FEE:
        tx.fee = Double.valueOf(reader.nextDouble() * 1e8).longValue();
        break;
      case TYPE:
        tx.type = reader.nextString();
        break;
      case SHIELDED:
        tx.shielded = reader.nextBoolean();
        break;
      case INDEX:
        tx.index = reader.nextLong();
        break;
      case BLOCKHASH:
        tx.blockHash = reader.nextString();
        break;
      case BLOCKHEIGHT:
        tx.blockHeight = reader.nextLong();
        break;
      case VERSION:
        tx.version = reader.nextLong();
        break;
      case LOCKTIME:
        tx.locktime = reader.nextLong();
        break;
      case TIME:
        tx.time = reader.nextLong();
        break;
      case TIMESTAMP:
        tx.timestamp = reader.nextLong();
        break;
      case VIN:
        tx.vin = readTxInputs(reader);
        break;
      case VOUT:
        tx.vout = readTxOutputs(reader, null);
        break;
      case VJOINSPLIT:
        skipJoinSplits(reader);
        break;
      case VALUE:
        tx.value = Double.valueOf(reader.nextDouble() * 1e8).longValue();
        break;
      case OUTPUTVALUE:
        tx.outputValue = Double.valueOf(reader.nextDouble() * 1e8).longValue();
        break;
      case SHIELDEDVALUE:
        tx.shieldedValue = Double.valueOf(reader.nextDouble() * 1e8).longValue();
        break;
      default:
        reader.skipValue();
    }
  }

  reader.endObject();
  return tx;
}
 
Example 11
Source File: JSONParser.java    From guarda-android-wallets with GNU General Public License v3.0 4 votes vote down vote up
private static ZCashTransactionOutput readTxSingleOutput(JsonReader reader) throws IOException {
  ZCashTransactionOutput output = new ZCashTransactionOutput();
  reader.beginObject(); //output
  while (reader.peek() != JsonToken.END_OBJECT) {
    String name = reader.nextName();
    switch (name) {
      case N:
        output.n = reader.nextLong();
        break;
      case SCRIPTPUBKEY:
        reader.beginObject();
        while (reader.peek() != JsonToken.END_OBJECT) {
          name = reader.nextName();
          switch (name) {
            case ADDRESSES:
              reader.beginArray();
              while (reader.hasNext()) {
                output.address = reader.nextString();
              }
              reader.endArray();
              break;
            case ASM:
              output.asm = reader.nextString();
              break;
            case HEX:
              output.hex = reader.nextString();
              break;
            case REQSIGS:
              output.regSigs = reader.nextLong();
              break;
            case TYPE:
              output.type = reader.nextString();
              break;
            default:
              reader.skipValue();
          }
        }
        reader.endObject();
        break;
      case VALUE:
        output.value = Double.valueOf(reader.nextDouble() * 1e8).longValue();
        break;
      case VALUEZAT:
        output.value = reader.nextLong();
        break;
      default:
        reader.skipValue();
    }
  }

  reader.endObject(); //output end
  return output;
}
 
Example 12
Source File: AndroidPlacesApiJsonParser.java    From android-PlacesAutocompleteTextView with BSD 2-Clause "Simplified" License 4 votes vote down vote up
List<PlaceReview> readReviewsArray(JsonReader reader) throws IOException {
    List<PlaceReview> reviews = new ArrayList<>();

    reader.beginArray();
    while (reader.hasNext()) {
        List<RatingAspect> aspects = null;
        String authorName = null;
        String authorUrl = null;
        String language = null;
        int rating = -1;
        String text = null;
        long time = -1L;

        reader.beginObject();
        while (reader.hasNext()) {
            switch (reader.nextName()) {
                case "aspects":
                    aspects = readAspectsArray(reader);
                    break;
                case "author_name":
                    authorName = reader.nextString();
                    break;
                case "author_url":
                    authorUrl = reader.nextString();
                    break;
                case "language":
                    language = reader.nextString();
                    break;
                case "rating":
                    rating = reader.nextInt();
                    break;
                case "text":
                    text = reader.nextString();
                    break;
                case "time":
                    time = reader.nextLong();
                    break;
                default:
                    reader.skipValue();
                    break;
            }
        }
        reader.endObject();
        reviews.add(new PlaceReview(aspects, authorName, authorUrl, language, rating, text, time));
    }
    reader.endArray();
    return reviews;
}