当前位置: 首页>>代码示例>>Java>>正文


Java JsonReader类代码示例

本文整理汇总了Java中com.squareup.moshi.JsonReader的典型用法代码示例。如果您正苦于以下问题:Java JsonReader类的具体用法?Java JsonReader怎么用?Java JsonReader使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


JsonReader类属于com.squareup.moshi包,在下文中一共展示了JsonReader类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: fromJson

import com.squareup.moshi.JsonReader; //导入依赖的package包/类
@FromJson
List<Applet> fromJson(JsonReader jsonReader, JsonAdapter<Applet> delegate) throws IOException {
    List<Applet> applets = new ArrayList<>();
    jsonReader.beginObject();
    while (jsonReader.hasNext()) {
        int index = jsonReader.selectName(OPTIONS);
        switch (index) {
            case -1:
                jsonReader.skipValue();
                break;
            case 0:
                jsonReader.beginArray();
                while (jsonReader.hasNext()) {
                    Applet applet = delegate.fromJson(jsonReader);
                    applets.add(applet);
                }
                jsonReader.endArray();
                break;
            default:
                throw new IllegalStateException("Unknown index: " + index);
        }
    }
    jsonReader.endObject();

    return applets;
}
 
开发者ID:IFTTT,项目名称:IFTTTSDK-Android,代码行数:27,代码来源:AppletListJsonAdapter.java

示例2: fromJson

import com.squareup.moshi.JsonReader; //导入依赖的package包/类
@Override
public Folder fromJson(JsonReader in) throws IOException {
    if (in.peek() == JsonReader.Token.NULL) {
        in.nextNull();
        return null;
    }
    Folder folder = new Folder();
    in.beginObject();
    while (in.hasNext()) {
        String name = in.nextName();
        switch (name) {
            case "id":
                folder.setId(in.nextLong());
                break;
            case "name":
                folder.setName(in.nextString());
                break;
            default:
                Log.w(TAG, "Unknown value in folder json: " + name);
                in.skipValue();
                break;
        }
    }
    in.endObject();
    return folder;
}
 
开发者ID:schaal,项目名称:ocreader,代码行数:27,代码来源:FolderTypeAdapter.java

示例3: readAvatar

import com.squareup.moshi.JsonReader; //导入依赖的package包/类
private void readAvatar(JsonReader in, User user, String name) throws IOException {
    in.beginObject();
    while(in.hasNext()) {
        String avatarName = in.nextName();
        switch (avatarName) {
            case "data":
                user.setAvatar(in.nextString());
                break;
            case "mime":
                user.setAvatarMime(in.nextString());
                break;
            default:
                Log.w(TAG, "Unknown value in avatar json: " + name);
                in.skipValue();
                break;
        }
    }
    in.endObject();
}
 
开发者ID:schaal,项目名称:ocreader,代码行数:20,代码来源:UserTypeAdapter.java

示例4: readWarnings

import com.squareup.moshi.JsonReader; //导入依赖的package包/类
private void readWarnings(JsonReader in, Status status) throws IOException {
    in.beginObject();
    while(in.hasNext()) {
        String name = in.nextName();
        switch (name) {
            case "improperlyConfiguredCron":
                status.setImproperlyConfiguredCron(in.nextBoolean());
                break;
            case "incorrectDbCharset":
                // TODO: 11/9/17 Show warning 
                in.skipValue();
                break;
            default:
                Log.w(TAG, "Unknown value in status warnings json: " + name);
                in.skipValue();
        }
    }
    in.endObject();
}
 
开发者ID:schaal,项目名称:ocreader,代码行数:20,代码来源:StatusTypeAdapter.java

示例5: compute

import com.squareup.moshi.JsonReader; //导入依赖的package包/类
@Override protected List<String> compute() {
  try (Response response = client.newCall(describeElasticsearchDomain).execute()) {
    if (!response.isSuccessful()) {
      throw new IllegalStateException(response.body().string());
    }

    JsonReader endpointReader =
        enterPath(JsonReader.of(response.body().source()), "DomainStatus", "Endpoint");
    checkArgument(endpointReader != null, "DomainStatus.Endpoint wasn't present in response");

    String endpoint = endpointReader.nextString();
    if (!endpoint.startsWith("https://")) {
      endpoint = "https://" + endpoint;
    }
    log.fine("using endpoint " + endpoint);
    return Collections.singletonList(endpoint);
  } catch (IOException e) {
    throw new IllegalStateException("couldn't lookup domain endpoint", e);
  }
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:21,代码来源:ElasticsearchDomainEndpoint.java

示例6: collectBucketKeys

import com.squareup.moshi.JsonReader; //导入依赖的package包/类
@Override
protected ListenableFuture<List<String>> collectBucketKeys(String[] indices,
    QueryBuilder query, AbstractAggregationBuilder... aggregations) {
  SearchSourceBuilder elasticQuery = new SearchSourceBuilder().query(query).size(0);
  for (AbstractAggregationBuilder aggregation : aggregations) {
    elasticQuery.aggregation(aggregation);
  }

  Call searchRequest = http.newCall(new Request.Builder().url(lenientSearch(indices, SPAN))
      .post(RequestBody.create(APPLICATION_JSON, elasticQuery.toString()))
      .tag("search-spansAggregations").build());

  return new CallbackListenableFuture<List<String>>(searchRequest) {
    List<String> convert(ResponseBody responseBody) throws IOException {
      Set<String> result = collectValuesNamed(JsonReader.of(responseBody.source()), "key");
      return Util.sortedList(result);
    }
  }.enqueue();
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:20,代码来源:HttpClient.java

示例7: fromJson

import com.squareup.moshi.JsonReader; //导入依赖的package包/类
@Override
public Annotation fromJson(JsonReader reader) throws IOException {
  Annotation.Builder result = Annotation.builder();
  reader.beginObject();
  while (reader.hasNext()) {
    switch (reader.nextName()) {
      case "timestamp":
        result.timestamp(reader.nextLong());
        break;
      case "value":
        result.value(reader.nextString());
        break;
      case "endpoint":
        result.endpoint(ENDPOINT_ADAPTER.fromJson(reader));
        break;
      default:
        reader.skipValue();
    }
  }
  reader.endObject();
  return result.build();
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:23,代码来源:ZipkinAdapters.java

示例8: enterPath

import com.squareup.moshi.JsonReader; //导入依赖的package包/类
@Nullable
public static JsonReader enterPath(JsonReader reader, String path) throws IOException {
  try {
    if (reader.peek() != JsonReader.Token.BEGIN_OBJECT) return null;
  } catch (EOFException e) {
    return null;
  }
  reader.beginObject();
  while (reader.hasNext()) {
    if (reader.nextName().equals(path) && reader.peek() != JsonReader.Token.NULL) {
      return reader;
    } else {
      reader.skipValue();
    }
  }
  reader.endObject();
  return null;
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:19,代码来源:JsonReaders.java

示例9: fromJson

import com.squareup.moshi.JsonReader; //导入依赖的package包/类
@Override
public ResourceIdentifier fromJson(JsonReader reader) throws IOException {
    ResourceIdentifier object = new ResourceIdentifier();
    reader.beginObject();
    while (reader.hasNext()) {
        switch (reader.nextName()) {
            case "id":
                object.setId(nextNullableString(reader));
                break;
            case "type":
                object.setType(nextNullableString(reader));
                break;
            case "meta":
                object.setMeta(nextNullableObject(reader, jsonBufferJsonAdapter));
                break;
            default:
                reader.skipValue();
                break;
        }
    }
    reader.endObject();
    return object;
}
 
开发者ID:kamikat,项目名称:moshi-jsonapi,代码行数:24,代码来源:ResourceIdentifier.java

示例10: fromJson

import com.squareup.moshi.JsonReader; //导入依赖的package包/类
@Override
public HasOne<T> fromJson(JsonReader reader) throws IOException {
    HasOne<T> relationship = new HasOne<>();
    reader.beginObject();
    while (reader.hasNext()) {
        switch (reader.nextName()) {
            case "data":
                relationship.set(nextNullableObject(reader, resourceIdentifierJsonAdapter));
                break;
            case "meta":
                relationship.setMeta(nextNullableObject(reader, jsonBufferJsonAdapter));
                break;
            case "links":
                relationship.setLinks(nextNullableObject(reader, jsonBufferJsonAdapter));
                break;
            default:
                reader.skipValue();
                break;
        }
    }
    reader.endObject();
    return relationship;
}
 
开发者ID:kamikat,项目名称:moshi-jsonapi,代码行数:24,代码来源:HasOne.java

示例11: fromJson

import com.squareup.moshi.JsonReader; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override public <T> T fromJson(File file, Class<T> classOfT) throws RuntimeException {
  BufferedSource bufferedSource = null;
  try {
    bufferedSource = Okio.buffer(Okio.source(file));
    JsonAdapter<T> jsonAdapter = moshi.adapter(classOfT);
    return jsonAdapter.fromJson(JsonReader.of(bufferedSource));
  } catch (IOException e) {
    throw new RuntimeException(e);
  } finally {
    if(bufferedSource != null){
      try {
        bufferedSource.close();
      } catch (IOException ignored) {
      }
    }
  }
}
 
开发者ID:VictorAlbertos,项目名称:Jolyglot,代码行数:21,代码来源:MoshiSpeaker.java

示例12: jsonToServiceError

import com.squareup.moshi.JsonReader; //导入依赖的package包/类
private ServiceError jsonToServiceError(Response response)
{
    ServiceError serviceError = null;
    BufferedSource source = response.body()
            .source();
    JsonReader reader = JsonReader.of(source);
    try
    {
        reader.beginObject();
        while(reader.hasNext())
        {
            String name = reader.nextName();
            if(name.equals("requestError"))
            {
                ServiceException serviceException = getServiceException(reader);
                serviceError = initServiceError(serviceError, serviceException);
            }
        }
    }
    catch(IOException e)
    {
        e.printStackTrace();
    }
    return serviceError;
}
 
开发者ID:DevAlves1993,项目名称:OSmsJava,代码行数:26,代码来源:OSms.java

示例13: read

import com.squareup.moshi.JsonReader; //导入依赖的package包/类
@FromJson
public AnInterface read(JsonReader jsonReader) throws IOException {
    jsonReader.beginObject();

    String name = null;
    while (jsonReader.hasNext()) {
        switch (jsonReader.nextName()) {
            case "name":
                name = jsonReader.nextString();
                break;
        }
    }

    jsonReader.endObject();
    return new AnImplementation(name);
}
 
开发者ID:apptik,项目名称:jus,代码行数:17,代码来源:MoshiConverterFactoryTest.java

示例14: read

import com.squareup.moshi.JsonReader; //导入依赖的package包/类
@FromJson public AnInterface read(JsonReader jsonReader) throws IOException {
  jsonReader.beginObject();

  String name = null;
  while (jsonReader.hasNext()) {
    switch (jsonReader.nextName()) {
      case "name":
        name = jsonReader.nextString();
        break;
    }
  }

  jsonReader.endObject();
  return new AnImplementation(name);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:16,代码来源:MoshiConverterFactoryTest.java

示例15: readQualified

import com.squareup.moshi.JsonReader; //导入依赖的package包/类
@FromJson @Qualifier public String readQualified(JsonReader reader) throws IOException {
  String string = reader.nextString();
  if (string.equals("qualified!")) {
    return "it worked!";
  }
  throw new AssertionError("Found: " + string);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:8,代码来源:MoshiConverterFactoryTest.java


注:本文中的com.squareup.moshi.JsonReader类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。