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