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


Java JsonStreamParser.next方法代码示例

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


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

示例1: testGetMessageTypeTime

import com.google.gson.JsonStreamParser; //导入方法依赖的package包/类
@Test
public void testGetMessageTypeTime() {
   Gson gson = new Gson();
   String json = "{\n" +
      "  \"scannerID\": \"Room203\",\n" +
      "  \"uuid\": \"DAF246CEF20311E4B116123B93F75CBA\",\n" +
      "  \"code\": 533,\n" +
      "  \"manufacturer\": 19456,\n" +
      "  \"major\": 203,\n" +
      "  \"minor\": 20,\n" +
      "  \"power\": -62,\n" +
      "  \"calibratedPower\": -62,\n" +
      "  \"rssi\": -67,\n" +
      "  \"messageType\": 1,\n" +
      "  \"time\": 1426016481227\n" +
      "}";
   JsonStreamParser parser = new JsonStreamParser(json);
   JsonElement jse = parser.next();
   JsonPrimitive messageType = jse.getAsJsonObject().getAsJsonPrimitive("messageType");
   System.out.printf("jse.messageType = %d\n", messageType.getAsInt());
   JsonPrimitive time = jse.getAsJsonObject().getAsJsonPrimitive("time");
   System.out.printf("jse.time = %d\n", time.getAsLong());
}
 
开发者ID:starksm64,项目名称:RaspberryPiBeaconParser,代码行数:24,代码来源:TestBeaconSerialization.java

示例2: 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

示例3: 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

示例4: 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

示例5: 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


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