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


Java FromJson类代码示例

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


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

示例1: fromJson

import com.squareup.moshi.FromJson; //导入依赖的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.FromJson; //导入依赖的package包/类
@FromJson
boolean fromJson(final Object json) {
    final String jsonString = json.toString();
    final Integer jsonInteger = toIntOrNull(jsonString);

    if (jsonInteger != null) {
        if (jsonInteger == 1) {
            return true;
        } else if (jsonInteger == 0) {
            return false;
        }
    } else {
        if ("true".equals(jsonString)) {
            return true;
        } else if ("false".equals(jsonString)) {
            return false;
        }
    }

    throw new JsonDataException("Unable to map " + json + " to a boolean value");
}
 
开发者ID:proxer,项目名称:ProxerLibJava,代码行数:22,代码来源:PrimitiveBooleanAdapter.java

示例3: fromJson

import com.squareup.moshi.FromJson; //导入依赖的package包/类
@FromJson
EpisodeInfo fromJson(final IntermediateEpisodeInfo json) {
    final List<Episode> episodes = new ArrayList<>(json.episodes.size());

    for (IntermediateEpisode episode : json.episodes) {
        if (json.category == Category.ANIME) {
            episodes.add(new AnimeEpisode(episode.number, episode.language,
                    new HashSet<>(Arrays.asList(episode.hosters.split(DELIMITER))),
                    Arrays.asList(episode.hosterImages.split(DELIMITER))));
        } else {
            episodes.add(new MangaEpisode(episode.number, episode.language, episode.title));
        }
    }

    return new EpisodeInfo(json.firstEpisode, json.lastEpisode, json.category, json.availableLanguages,
            json.userState, episodes);
}
 
开发者ID:proxer,项目名称:ProxerLibJava,代码行数:18,代码来源:EpisodeInfoAdapter.java

示例4: fromJson

import com.squareup.moshi.FromJson; //导入依赖的package包/类
@FromJson
public Stream.TYPE fromJson(String type) {
    if (type.equalsIgnoreCase(Stream.TYPE.AUDIO.toString())) {
        return Stream.TYPE.AUDIO;
    }
    if (type.equalsIgnoreCase(Stream.TYPE.MUSIC.toString())) {
        return Stream.TYPE.MUSIC;
    }
    if (type.equalsIgnoreCase(Stream.TYPE.SLIDES.toString())) {
        return Stream.TYPE.SLIDES;
    }
    if (type.equalsIgnoreCase(Stream.TYPE.VIDEO.toString())) {
        return Stream.TYPE.VIDEO;
    }
    return Stream.TYPE.UNKNOWN;
}
 
开发者ID:johnjohndoe,项目名称:Brockman,代码行数:17,代码来源:StreamTypeAdapter.java

示例5: fromJson

import com.squareup.moshi.FromJson; //导入依赖的package包/类
@FromJson
public Url.TYPE fromJson(String type) {
    if (type.equalsIgnoreCase(Url.TYPE.HLS.toString())) {
        return Url.TYPE.HLS;
    }
    if (type.equalsIgnoreCase(Url.TYPE.MP3.toString())) {
        return Url.TYPE.MP3;
    }
    if (type.equalsIgnoreCase(Url.TYPE.OPUS.toString())) {
        return Url.TYPE.OPUS;
    }
    if (type.equalsIgnoreCase(Url.TYPE.WEBM.toString())) {
        return Url.TYPE.WEBM;
    }
    return Url.TYPE.UNKNOWN;
}
 
开发者ID:johnjohndoe,项目名称:Brockman,代码行数:17,代码来源:UrlTypeAdapter.java

示例6: read

import com.squareup.moshi.FromJson; //导入依赖的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

示例7: read

import com.squareup.moshi.FromJson; //导入依赖的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

示例8: readQualified

import com.squareup.moshi.FromJson; //导入依赖的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

示例9: fromJson

import com.squareup.moshi.FromJson; //导入依赖的package包/类
@FromJson
Applet fromJson(AppletJson appletJson) throws IOException {
    Applet.Status status;
    if (appletJson.user_status == null) {
        status = Applet.Status.unknown;
    } else {
        status = Applet.Status.valueOf(appletJson.user_status);
    }

    return new Applet(appletJson.id, appletJson.name, appletJson.description, status, appletJson.published_at,
            appletJson.enabled_count, appletJson.last_run_at, appletJson.url, appletJson.embedded_url,
            appletJson.services);
}
 
开发者ID:IFTTT,项目名称:IFTTTSDK-Android,代码行数:14,代码来源:AppletJsonAdapter.java

示例10: fromJson

import com.squareup.moshi.FromJson; //导入依赖的package包/类
@FromJson
public Date fromJson(String value) {
    try {
        return DATE_FORMAT.parse(value);
    } catch (ParseException e) {
        return null;
    }
}
 
开发者ID:ErikHellman,项目名称:AutoValueDemo,代码行数:9,代码来源:MainActivity.java

示例11: fromJson

import com.squareup.moshi.FromJson; //导入依赖的package包/类
@FromJson
public RealmList<RealmString> fromJson(final List<String> inList) {
    final RealmList<RealmString> outList = new RealmList<>();

    for (final String s : inList) {
        outList.add(new RealmString(s));
    }

    return outList;
}
 
开发者ID:toshiapp,项目名称:toshi-android-client,代码行数:11,代码来源:RealmListAdapter.java

示例12: fromJson

import com.squareup.moshi.FromJson; //导入依赖的package包/类
@FromJson
@FormattedTime
Date fromJson(String time){
    DateTimeFormatter format = DateTimeFormat.forPattern("yyyy-MM-dd'T'HH:mm:ss'Z'");
    DateTime t = format.withZoneUTC().parseDateTime(time);
    return t.toDate();
}
 
开发者ID:Meisolsson,项目名称:GitHubSdk,代码行数:8,代码来源:FormattedTimeAdapter.java

示例13: fromJson

import com.squareup.moshi.FromJson; //导入依赖的package包/类
@FromJson
@FalseToNull
EthSyncingResult fromJson(EthSyncingResultJson in) {
    EthSyncingResult result = new EthSyncingResult();
    result.currentBlock = in.currentBlock;
    result.highestBlock = in.highestBlock;
    result.knownStates = in.knownStates;
    result.pulledStates = in.pulledStates;
    result.startingBlock = in.startingBlock;
    return result;
}
 
开发者ID:biafra23,项目名称:EtherWallet,代码行数:12,代码来源:EthSyncingResultAdapter.java

示例14: fromJson

import com.squareup.moshi.FromJson; //导入依赖的package包/类
@Nullable
@FromJson
Void fromJson(final String json) {
    if (json.equals(JSON_NULL)) {
        return null;
    } else {
        throw new JsonDataException("Void field can only host null values. Actual: " + json);
    }
}
 
开发者ID:proxer,项目名称:ProxerLibJava,代码行数:10,代码来源:VoidAdapter.java

示例15: fromJson

import com.squareup.moshi.FromJson; //导入依赖的package包/类
@FromJson
@Nullable
RatingDetails fromJson(final String json) throws IOException {
    if (json.isEmpty() || json.equals(INVALID_ARRAY)) {
        return new RatingDetails(0, 0, 0, 0, 0);
    } else {
        return internalAdapter.fromJson(json);
    }
}
 
开发者ID:proxer,项目名称:ProxerLibJava,代码行数:10,代码来源:FixRatingDetailsAdapter.java


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