本文整理汇总了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;
}
示例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");
}
示例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);
}
示例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;
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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;
}
}
示例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;
}
示例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();
}
示例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;
}
示例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);
}
}
示例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);
}
}