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


Java JsonStreamParser.hasNext方法代码示例

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


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

示例1: save

import com.google.gson.JsonStreamParser; //导入方法依赖的package包/类
@POST
@Path("save")
@Consumes(MediaType.APPLICATION_JSON)
@Produces(MediaType.APPLICATION_JSON)
public Response save(String json) throws Exception {
    JsonStreamParser jsonStreamParser = new JsonStreamParser(json);
    if (!jsonStreamParser.hasNext()) {
        return Response.status(Status.BAD_REQUEST).build();
    }
    JsonObject saveObject = jsonStreamParser.next().getAsJsonObject();
    // get navigation
    MCRNavigation newNavigation = MCRWCMSNavigationManager.fromJSON(saveObject);
    // save navigation
    MCRWCMSNavigationManager.save(newNavigation);
    // save content
    JsonArray items = saveObject.get(MCRWCMSNavigationProvider.JSON_ITEMS).getAsJsonArray();
    getContentManager().save(items);
    return Response.ok().build();
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:20,代码来源:MCRWCMSNavigationResource.java

示例2: getCategoryIDMap

import com.google.gson.JsonStreamParser; //导入方法依赖的package包/类
public static HashMap<MCRCategoryID, String> getCategoryIDMap(String json) {
    HashMap<MCRCategoryID, String> categories = new HashMap<>();
    JsonStreamParser jsonStreamParser = new JsonStreamParser(json);
    if (jsonStreamParser.hasNext()) {
        JsonArray saveObjArray = jsonStreamParser.next().getAsJsonArray();
        for (JsonElement jsonElement : saveObjArray) {
            //jsonObject.item.id.rootid
            JsonObject root = jsonElement.getAsJsonObject();
            String rootId = root.getAsJsonObject("item").getAsJsonObject("id").getAsJsonPrimitive("rootid")
                .getAsString();

            String state = root.getAsJsonPrimitive("state").getAsString();
            JsonElement parentIdJSON = root.get("parentId");
            if (parentIdJSON != null && parentIdJSON.isJsonPrimitive()
                && "_placeboid_".equals(parentIdJSON.getAsString())) {
                state = "new";
            }

            categories.put(MCRCategoryID.rootID(rootId), state);
        }
    } else {
        return null;
    }
    return categories;
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:26,代码来源:MCRCategUtils.java

示例3: getTrackInfo

import com.google.gson.JsonStreamParser; //导入方法依赖的package包/类
public static List<JsonObject> getTrackInfo(String json)
{
	Gson gson = new Gson();
	List<JsonObject> jsonTrackList = new ArrayList<JsonObject>();
	JsonStreamParser parser = new JsonStreamParser( new StringReader(json.replace("},{", "}{")));
	while (parser.hasNext())
	{
		jsonTrackList.add(gson.fromJson(parser.next(),JsonObject.class));
	}
	return jsonTrackList;
}
 
开发者ID:scriptkittie,项目名称:bandcamp-api,代码行数:12,代码来源:JSONUtil.java

示例4: save

import com.google.gson.JsonStreamParser; //导入方法依赖的package包/类
@POST
@Path("save")
@MCRRestrictedAccess(MCRClassificationWritePermission.class)
@Consumes(MediaType.APPLICATION_JSON)
public Response save(String json) {
    JsonStreamParser jsonStreamParser = new JsonStreamParser(json);
    if (jsonStreamParser.hasNext()) {
        JsonArray saveObjArray = jsonStreamParser.next().getAsJsonArray();
        List<JsonObject> saveList = new ArrayList<>();
        for (JsonElement jsonElement : saveObjArray) {
            saveList.add(jsonElement.getAsJsonObject());
        }
        saveList.sort(new IndexComperator());
        for (JsonObject jsonObject : saveList) {
            String status = getStatus(jsonObject);
            SaveElement categ = getCateg(jsonObject);
            MCRJSONCategory parsedCateg = parseJson(categ.getJson());
            if ("update".equals(status)) {
                new UpdateOp(parsedCateg, jsonObject).run();
            } else if ("delete".equals(status)) {
                deleteCateg(categ.getJson());
            } else {
                return Response.status(Status.BAD_REQUEST).build();
            }
        }
        //            Status.CONFLICT
        return Response.status(Status.OK).build();
    } else {
        return Response.status(Status.BAD_REQUEST).build();
    }
}
 
开发者ID:MyCoRe-Org,项目名称:mycore,代码行数:32,代码来源:MCRClassificationEditorResource.java

示例5: load

import com.google.gson.JsonStreamParser; //导入方法依赖的package包/类
private void load(Reader in) {
    configTab = new HashMap<>();
    JsonStreamParser parser = new JsonStreamParser(in);
    JsonElement root = null;
    if(parser.hasNext()) {
        root = parser.next();
    }
    if(root != null && root.isJsonObject()) {
        flatten(null, root);
    }
    LOGGER.debug("json configuration loaded: {}", configTab);
}
 
开发者ID:flipkart-incubator,项目名称:polyguice,代码行数:13,代码来源:JsonConfiguration.java

示例6: testReadJsonFile

import com.google.gson.JsonStreamParser; //导入方法依赖的package包/类
@Test
public void testReadJsonFile() throws Exception {
   FileReader fr = new FileReader("/tmp/testWriteJson.json");
   Gson gson = new Gson();
   JsonStreamParser jsp = new JsonStreamParser(fr);
   int count = 0;
   while (jsp.hasNext()) {
      JsonElement jse = jsp.next();
      Beacon beacon = gson.fromJson(jse, Beacon.class);
      System.out.printf("%d: %s\n", count++, beacon);
   }
   fr.close();
}
 
开发者ID:starksm64,项目名称:RaspberryPiBeaconParser,代码行数:14,代码来源:TestSendRecv.java

示例7: testReadJson

import com.google.gson.JsonStreamParser; //导入方法依赖的package包/类
@Test
public void testReadJson() throws Exception {
   FileReader fr = new FileReader("/tmp/testWriteJson.json");
   Gson gson = new Gson();
   JsonStreamParser parser = new JsonStreamParser(fr);
   while(parser.hasNext()) {
      JsonElement jse = parser.next();
      Beacon beacon = gson.fromJson(jse, Beacon.class);
      System.out.printf("Beacon from json:%s\n", beacon);
   }
}
 
开发者ID:starksm64,项目名称:RaspberryPiBeaconParser,代码行数:12,代码来源:TestBeaconSerialization.java

示例8: parseOnly

import com.google.gson.JsonStreamParser; //导入方法依赖的package包/类
@Override
public void parseOnly(File file, Blackhole bh) throws Exception {
    JsonStreamParser jsp = new JsonStreamParser(new FileReader(file));
    while (jsp.hasNext()) {
        bh.consume(jsp.next());
      }
}
 
开发者ID:salyh,项目名称:jsr353-benchmark,代码行数:8,代码来源:GsonParser.java

示例9: start

import com.google.gson.JsonStreamParser; //导入方法依赖的package包/类
public void start() {
	Runnable thread = new Runnable() {

		/*
		 * (non-Javadoc)
		 * 
		 * @see java.lang.Thread#run()
		 */
		@Override
		public void run() {
			Tracker tracker = new Tracker(getUser(), getHostName(),
					getIp(), getOs(), System.currentTimeMillis(), getInitiator());

			AutoRetryHttpClient client = new AutoRetryHttpClient(
					new DefaultServiceUnavailableRetryStrategy(3, 3000));
			HttpPost request = createRequest(tracker);
			HttpHost httpHost = createHttpHost();

			try {
				HttpResponse resp = client.execute(httpHost, request);
				int code = resp.getStatusLine().getStatusCode();
				if (HttpResponseStatus.OK.code() == code) {
					InputStream is = null;
					try {
						is = resp.getEntity().getContent();
						is = new BufferedInputStream(is);
						InputStreamReader reader = new InputStreamReader(is);
						JsonStreamParser parser = new JsonStreamParser(
								reader);
						while (parser.hasNext()) {
							JsonElement json = parser.next();
							LOGGER.debug("Tracking data sent: " + json);
						}
					} finally {
						if (is != null) {
							is.close();
						}
					}

				} else {
					LOGGER.error(ERROR_FAILED_TO_SEND);
					LOGGER.debug("Response code: " + code);
				}
			} catch (IOException e) {
				LOGGER.warn(ERROR_FAILED_TO_SEND);
			}
		}

	};

	m_scheduledService.scheduleAtFixedRate(thread, 0, m_interval,
			TimeUnit.SECONDS);
}
 
开发者ID:eBay,项目名称:ServiceCOLDCache,代码行数:54,代码来源:TrackerClient.java

示例10: readSentence

import com.google.gson.JsonStreamParser; //导入方法依赖的package包/类
public static AnnoSentence readSentence(JsonStreamParser reader) throws IOException {
    if(!reader.hasNext()) {
        return null;
    }
    JsonObject jo = reader.next().getAsJsonObject();
    AnnoSentence sent = new AnnoSentence();
    for (Entry<String,JsonElement> entry : jo.entrySet()) {
        String key = entry.getKey();
        JsonElement val = entry.getValue();
        // Process each key in this sentence.
        if (key.equals("words")) {
            sent.setWords(getListOfStrings(key, val));
        } else if (key.equals("prefixes")) {
            sent.setPrefixes(getListOfStrings(key, val));
        } else if (key.equals("lemmas")) {
            sent.setLemmas(getListOfStrings(key, val));
        } else if (key.equals("posTags")) {
            sent.setPosTags(getListOfStrings(key, val));
        } else if (key.equals("cposTags")) {
            sent.setCposTags(getListOfStrings(key, val));
        } else if (key.equals("strictPosTags")) {
            List<String> tags = getListOfStrings(key, val);
            sent.setStrictPosTags(tags.stream().map(x -> StrictPosTag.valueOf(x)).collect(Collectors.toList()));
        } else if (key.equals("clusters")) {
            sent.setClusters(getListOfStrings(key, val));
        } else if (key.equals("chunks")) {
            sent.setChunks(getListOfStrings(key, val));
        } else if (key.equals("neTags")) {
            sent.setNeTags(getListOfStrings(key, val));
        } else if (key.equals("parents")) {
            sent.setParents(getIntArray(key, val));
        } else if (key.equals("deprels")) {
            sent.setDeprels(getListOfStrings(key, val));
        } else if (key.equals("naryTree")) {
            sent.setNaryTree(NaryTree.fromTreeInPtbFormat(val.getAsString()));
        } else if (key.equals("namedEntities")) {
            if (sent.getWords() == null) {
                throw new IllegalStateException("Invalid file format: words must appear before namedEntities in the JSON.");
            }
            sent.setNamedEntities(JsonConcatWriter.nesFromJson(val.getAsString(), sent.size()));
        } else if (key.equals("nePairs")) {
            sent.setNePairs(JsonConcatWriter.nePairsFromJson(val.getAsString()));
        } else if (key.equals("relLabels")) {
            sent.setRelLabels(getListOfStrings(key, val));
        } else{
            // Not supported: 
            // - embedIds (IntArrayList)
            // - feats (List<List<String>>)
            // - depEdgeMask (DepEdgeMask)
            // - srlGraph (SrlGraph)
            // - knownPreds (IntHashSet)
            // - namedEntitiesInContext
            // - relations (RelationMentions)
            // - relationsInContext
            throw new RuntimeException("Unsupported key:" + key);
        }
    }
    
    return sent;
}
 
开发者ID:mgormley,项目名称:pacaya-nlp,代码行数:61,代码来源:JsonConcatReader.java


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