mirror of https://github.com/FongMi/TV.git
parent
54c5aa920d
commit
fe0bddb687
@ -1,19 +1,22 @@ |
||||
package com.fongmi.android.tv.gson; |
||||
|
||||
import com.fongmi.android.tv.bean.Url; |
||||
import com.google.gson.JsonArray; |
||||
import com.google.gson.JsonDeserializationContext; |
||||
import com.google.gson.JsonDeserializer; |
||||
import com.google.gson.JsonElement; |
||||
import com.google.gson.JsonParseException; |
||||
|
||||
import java.lang.reflect.Type; |
||||
import java.util.List; |
||||
|
||||
public class UrlAdapter implements JsonDeserializer<String> { |
||||
public class UrlAdapter implements JsonDeserializer<Url> { |
||||
|
||||
@Override |
||||
public String deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { |
||||
if (!json.isJsonArray()) return json.getAsString(); |
||||
List<JsonElement> elements = json.getAsJsonArray().asList(); |
||||
return elements.size() < 2 ? "" : elements.get(1).getAsString(); |
||||
public Url deserialize(JsonElement json, Type typeOfT, JsonDeserializationContext context) throws JsonParseException { |
||||
Url url = new Url(); |
||||
if (!json.isJsonArray()) return url.add(json.getAsString()); |
||||
JsonArray array = json.getAsJsonArray(); |
||||
for (int i = 0; i < array.size(); i += 2) url.add(array.get(i).getAsString(), array.get(i + 1).getAsString()); |
||||
return url; |
||||
} |
||||
} |
||||
|
||||
Loading…
Reference in new issue