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


Java JsonArray.iterator方法代码示例

本文整理汇总了Java中com.google.gson.JsonArray.iterator方法的典型用法代码示例。如果您正苦于以下问题:Java JsonArray.iterator方法的具体用法?Java JsonArray.iterator怎么用?Java JsonArray.iterator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.gson.JsonArray的用法示例。


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

示例1: parseAsArrayList

import com.google.gson.JsonArray; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> ArrayList<T> parseAsArrayList(JsonElement json, T type) {
    ArrayList<T> newArray = new ArrayList<T>();
    Gson gson = new Gson();

    JsonArray array= json.getAsJsonArray();
    Iterator<JsonElement> iterator = array.iterator();

    while(iterator.hasNext()){
        JsonElement json2 = iterator.next();
        T object = (T) gson.fromJson(json2, (Class<?>)type);
        newArray.add(object);
    }

    return newArray;
}
 
开发者ID:FlavioSantoro92,项目名称:Pand,代码行数:17,代码来源:DAOJson.java

示例2: getList

import com.google.gson.JsonArray; //导入方法依赖的package包/类
public <T extends BaseModel> List<T> getList() {

        List<T> modelList = new ArrayList<T>();

        JsonElement outerJson = new JsonParser().parse(this.body);
        JsonArray array = outerJson.getAsJsonArray();
        Iterator iterator = array.iterator();

        while (iterator.hasNext()) {
            JsonElement innerJson = (JsonElement) iterator.next();
            Gson gson = new Gson();
            T code = gson.fromJson(innerJson, this.type);
            modelList.add(code);
        }
        return modelList;
    }
 
开发者ID:EhsanMashhadi,项目名称:RepositoryPattern,代码行数:17,代码来源:Response.java

示例3: primaryKeysFromJson

import com.google.gson.JsonArray; //导入方法依赖的package包/类
public static <PK extends PrimaryKey<PK>> List<PK> primaryKeysFromJson(Class<PK> pkClass, Fielder<PK> fielder,
		JsonArray json){
	List<PK> pks = new ArrayList<>();
	if(json == null){
		return pks;
	}
	Iterator<JsonElement> iter = json.iterator();
	while(iter.hasNext()){
		JsonObject jsonPk = iter.next().getAsJsonObject();
		PK pk = ReflectionTool.create(pkClass);
		primaryKeyFromJson(pk, fielder, jsonPk);
		pks.add(pk);
	}
	return pks;
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:16,代码来源:JsonDatabeanTool.java

示例4: databeansFromJson

import com.google.gson.JsonArray; //导入方法依赖的package包/类
public static <PK extends PrimaryKey<PK>,D extends Databean<PK,D>>
List<D> databeansFromJson(Supplier<D> databeanSupplier, DatabeanFielder<PK,D> fielder, JsonArray json){
	List<D> databeans = new ArrayList<>();
	if(json == null){
		return databeans;
	}
	Iterator<JsonElement> iter = json.iterator();
	while(iter.hasNext()){
		JsonObject jsonDatabean = iter.next().getAsJsonObject();
		D databean = databeanFromJson(databeanSupplier, fielder, jsonDatabean);
		databeans.add(databean);
	}
	return databeans;
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:15,代码来源:JsonDatabeanTool.java

示例5: getCachedSkin

import com.google.gson.JsonArray; //导入方法依赖的package包/类
private SkinData getCachedSkin(){
    JsonObject jsonFile = getChacheFile(plugin);
    JsonArray oldskindata = jsonFile.getAsJsonArray("skindata");
    Iterator it = oldskindata.iterator();
    SkinData skin = null;
    while(it.hasNext()){
        JsonElement element = (JsonElement) it.next();
        if(element.getAsJsonObject().get("id").getAsInt()==this.npcid){
            String value = element.getAsJsonObject().get("value").getAsString();
            String signature = element.getAsJsonObject().get("signature").getAsString();
            skin = new SkinData(value, signature);
        }
    }
    return skin;
}
 
开发者ID:eltrueno,项目名称:TruenoNPC,代码行数:16,代码来源:TruenoNPC_v1_8_r3.java

示例6: cacheSkin

import com.google.gson.JsonArray; //导入方法依赖的package包/类
private void cacheSkin(SkinData skindata){
    JsonObject jsonFile = getChacheFile(plugin);
    JsonArray newskindata = new JsonArray();
    if(jsonFile!=null){
        JsonArray oldskindata = jsonFile.getAsJsonArray("skindata");
        Iterator it = oldskindata.iterator();
        while(it.hasNext()){
            JsonElement element = (JsonElement) it.next();
            if(element.getAsJsonObject().get("id").getAsInt()==this.npcid){
                // element.getAsJsonObject().remove("value");
                //element.getAsJsonObject().remove("signature");
                //element.getAsJsonObject().addProperty("value", skindata.getValue());
                //element.getAsJsonObject().addProperty("signature", skindata.getSignature());
            }else {
                newskindata.add(element);
            }
        }
    }
    JsonObject skin = new JsonObject();
    skin.addProperty("id", this.npcid);
    skin.addProperty("value", skindata.getValue());
    skin.addProperty("signature", skindata.getSignature());
    newskindata.add(skin);

    JsonObject obj = new JsonObject();
    obj.add("skindata", newskindata);
    try {
        plugin.getDataFolder().mkdir();
        File file = new File(plugin.getDataFolder().getPath()+"/truenonpcdata.json");
        file.createNewFile();
        FileWriter writer = new FileWriter(file);
        writer.write(obj.toString());
        writer.close();

    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:eltrueno,项目名称:TruenoNPC,代码行数:39,代码来源:TruenoNPC_v1_8_r3.java

示例7: extractFromDataSources

import com.google.gson.JsonArray; //导入方法依赖的package包/类
public JsonObject extractFromDataSources(JsonDataSources sources) {
  usedTags = new HashSet<String>();
  usedSpeakers = new HashSet<String>();

  JsonObject result = new JsonObject();
  result.add(OutputJsonKeys.MainTypes.rooms.name(), extractRooms(sources));
  JsonArray speakers = extractSpeakers(sources);

  JsonArray tags = extractTags(sources);
  result.add(OutputJsonKeys.MainTypes.video_library.name(), extractVideoSessions(sources));

  result.add(OutputJsonKeys.MainTypes.sessions.name(), extractSessions(sources));

  // Remove tags that are not used on any session (b/14419126)
  Iterator<JsonElement> tagsIt = tags.iterator();
  while (tagsIt.hasNext()) {
    JsonElement tag = tagsIt.next();
    String tagName = get(tag.getAsJsonObject(), OutputJsonKeys.Tags.tag).getAsString();
    if (!usedTags.contains(tagName)) {
      tagsIt.remove();
    }
  }

  // Remove speakers that are not used on any session:
  Iterator<JsonElement> it = speakers.iterator();
  while (it.hasNext()) {
    JsonElement el = it.next();
    String id = get(el.getAsJsonObject(), OutputJsonKeys.Speakers.id).getAsString();
    if (!usedSpeakers.contains(id)) {
      it.remove();
    }
  }

  result.add(OutputJsonKeys.MainTypes.speakers.name(), speakers);
  result.add(OutputJsonKeys.MainTypes.tags.name(), tags);
  return result;
}
 
开发者ID:dreaminglion,项目名称:iosched-reader,代码行数:38,代码来源:DataExtractor.java

示例8: parseParams

import com.google.gson.JsonArray; //导入方法依赖的package包/类
protected Object parseParams(Object params, String method) {
	if (isNull(params)) {
		return null;
	}
	if (!(params instanceof JsonElement)) {
		return params;
	}
	JsonElement rawParams = (JsonElement) params;
	Type[] parameterTypes = getParameterTypes(method);
	if (parameterTypes.length == 1) {
		return fromJson(rawParams, parameterTypes[0]);
	}
	if (parameterTypes.length > 1 && rawParams instanceof JsonArray) {
		JsonArray array = (JsonArray) rawParams;
		List<Object> parameters = new ArrayList<Object>(Math.max(array.size(), parameterTypes.length));
		int index = 0;
		Iterator<JsonElement> iterator = array.iterator();
		while (iterator.hasNext()) {
			Type parameterType = index < parameterTypes.length ? parameterTypes[index] : null;
			Object parameter = fromJson(iterator.next(), parameterType);
			parameters.add(parameter);
			index++;
		}
		while (index < parameterTypes.length) {
			parameters.add(null);
			index++;
		}
		return parameters;
	}
	return rawParams;
}
 
开发者ID:tracymiranda,项目名称:dsp4e,代码行数:32,代码来源:DebugMessageTypeAdapterFactory.java


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