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


Java JsonObject类代码示例

本文整理汇总了Java中com.eclipsesource.json.JsonObject的典型用法代码示例。如果您正苦于以下问题:Java JsonObject类的具体用法?Java JsonObject怎么用?Java JsonObject使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getTle

import com.eclipsesource.json.JsonObject; //导入依赖的package包/类
public JsonObject getTle() {
	LOG.info("get tle");
	HttpGet m = new HttpGet(baseUrl + "/api/v1/admin/tle");
	m.addHeader("Authorization", "Bearer " + accessToken);
	HttpResponse response = null;
	try {
		response = httpclient.execute(m);
		int statusCode = response.getStatusLine().getStatusCode();
		String responseBody = EntityUtils.toString(response.getEntity());
		if (statusCode != HttpStatus.SC_OK) {
			LOG.info("response: " + responseBody);
			throw new RuntimeException("invalid status code: " + statusCode);
		}
		return (JsonObject) Json.parse(responseBody);
	} catch (Exception e) {
		throw new RuntimeException(e);
	} finally {
		if (response != null) {
			EntityUtils.consumeQuietly(response.getEntity());
		}
	}
}
 
开发者ID:dernasherbrezon,项目名称:r2cloud,代码行数:23,代码来源:RestClient.java

示例2: setup

import com.eclipsesource.json.JsonObject; //导入依赖的package包/类
public void setup(String keyword, String username, String password) {
	LOG.info("setup: " + username);
	HttpPost m = new HttpPost(baseUrl + "/api/v1/setup/setup");
	JsonObject json = Json.object();
	json.add("keyword", keyword);
	json.add("username", username);
	json.add("password", password);
	m.setEntity(new StringEntity(json.toString(), ContentType.APPLICATION_JSON));
	HttpResponse response = null;
	try {
		response = httpclient.execute(m);
		int statusCode = response.getStatusLine().getStatusCode();
		if (statusCode != HttpStatus.SC_OK) {
			LOG.info("response: " + EntityUtils.toString(response.getEntity()));
			throw new RuntimeException("invalid status code: " + statusCode);
		}
	} catch (Exception e) {
		throw new RuntimeException(e);
	} finally {
		if (response != null) {
			EntityUtils.consumeQuietly(response.getEntity());
		}
	}
}
 
开发者ID:dernasherbrezon,项目名称:r2cloud,代码行数:25,代码来源:RestClient.java

示例3: save

import com.eclipsesource.json.JsonObject; //导入依赖的package包/类
private static void save() throws Exception {
    final JsonObject runBench = new JsonObject();
    runBench.add("benchmarks", JsonHandler.global);
    runBench.add("time", System.currentTimeMillis());

    if (System.getProperty("commit") != null) {
        runBench.add("commit", System.getProperty("commit"));
    }
    if (System.getProperty("data") != null) {
        File targetDir = new File(System.getProperty("data"));
        if (!targetDir.exists()) {
            targetDir.mkdirs();
        }
        File output = new File(targetDir, System.currentTimeMillis() + ".json");
        FileWriter writer = new FileWriter(output);
        runBench.writeTo(writer);
        writer.flush();
        writer.close();
    } else {
        System.out.println(runBench.toString());
    }
}
 
开发者ID:datathings,项目名称:greycat,代码行数:23,代码来源:Runner.java

示例4: testMetersPopulatedArray

import com.eclipsesource.json.JsonObject; //导入依赖的package包/类
/**
 * Tests the result of the rest api GET when there are active meters.
 */
@Test
public void testMetersPopulatedArray() {
    setupMockMeters();
    replay(mockMeterService);
    replay(mockDeviceService);
    final WebTarget wt = target();
    final String response = wt.path("meters").request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("meters"));
    final JsonArray jsonMeters = result.get("meters").asArray();
    assertThat(jsonMeters, notNullValue());
    assertThat(jsonMeters, hasMeter(meter1));
    assertThat(jsonMeters, hasMeter(meter2));
    assertThat(jsonMeters, hasMeter(meter3));
    assertThat(jsonMeters, hasMeter(meter4));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:23,代码来源:MetersResourceTest.java

示例5: testMcastRoutePopulatedArray

import com.eclipsesource.json.JsonObject; //导入依赖的package包/类
/**
 * Tests the results of the REST API GET when there are active mcastroutes.
 */
@Test
public void testMcastRoutePopulatedArray() {
    initMcastRouteMocks();
    final Set<McastRoute> mcastRoutes = ImmutableSet.of(route1, route2, route3);
    expect(mockMulticastRouteService.getRoutes()).andReturn(mcastRoutes).anyTimes();
    replay(mockMulticastRouteService);

    final WebTarget wt = target();
    final String response = wt.path("mcast").request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("routes"));
    final JsonArray jsonMcastRoutes = result.get("routes").asArray();
    assertThat(jsonMcastRoutes, notNullValue());
    assertThat(jsonMcastRoutes, hasMcastRoute(route1));
    assertThat(jsonMcastRoutes, hasMcastRoute(route2));
    assertThat(jsonMcastRoutes, hasMcastRoute(route3));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:24,代码来源:MulticastRouteResourceTest.java

示例6: testSingleSubjectSingleConfig

import com.eclipsesource.json.JsonObject; //导入依赖的package包/类
/**
 * Tests the result of the rest api single subject single config GET when
 * there is a config.
 */
@Test
public void testSingleSubjectSingleConfig() {
    setUpConfigData();
    final WebTarget wt = target();
    final String response =
            wt.path("network/configuration/devices/device1/basic")
                    .request()
                    .get(String.class);

    final JsonObject result = Json.parse(response).asObject();
    Assert.assertThat(result, notNullValue());

    Assert.assertThat(result.names(), hasSize(2));

    checkBasicAttributes(result);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:21,代码来源:NetworkConfigWebResourceTest.java

示例7: testMeterSingleDeviceWithId

import com.eclipsesource.json.JsonObject; //导入依赖的package包/类
/**
 * Tests the result of a rest api GET for a device with meter id.
 */
@Test
public void testMeterSingleDeviceWithId() {
    setupMockMeters();

    expect(mockMeterService.getMeter(anyObject(), anyObject()))
            .andReturn(meter5).anyTimes();
    replay(mockMeterService);
    replay(mockDeviceService);

    final WebTarget wt = target();
    final String response = wt.path("meters/" + deviceId3.toString()
            + "/" + meter5.id().id()).request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("meters"));
    final JsonArray jsonMeters = result.get("meters").asArray();
    assertThat(jsonMeters, notNullValue());
    assertThat(jsonMeters, hasMeter(meter5));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:25,代码来源:MetersResourceTest.java

示例8: testGroupByDeviceIdAndAppCookie

import com.eclipsesource.json.JsonObject; //导入依赖的package包/类
/**
 * Test the result of a rest api GET with specifying device id and appcookie.
 */
@Test
public void testGroupByDeviceIdAndAppCookie() {
    setupMockGroups();
    expect(mockGroupService.getGroup(anyObject(), anyObject()))
            .andReturn(group5).anyTimes();
    replay(mockGroupService);
    final WebTarget wt = target();
    final String response = wt.path("groups/" + deviceId3 + "/" + "111")
            .request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("groups"));
    final JsonArray jsonFlows = result.get("groups").asArray();
    assertThat(jsonFlows, notNullValue());
    assertThat(jsonFlows, hasGroup(group5));
}
 
开发者ID:shlee89,项目名称:athena,代码行数:22,代码来源:GroupsResourceTest.java

示例9: Station

import com.eclipsesource.json.JsonObject; //导入依赖的package包/类
public Station(JPTI jpti, JsonObject json){
    this(jpti);
    try{
            name =json.getString(NAME,"駅名不明");
        subName=json.getString(SUBNAME,"");
        type=json.getInt(TYPE,0);
            description = json.getString(DESCRIPTION, "");
        lat=json.getString(LAT,"");
        lon=json.getString(LON,"");
        url=json.getString(URL,"");
        wheelcharBoarding=json.getString(WHEELCHAIR,"");
        JsonArray stopArray=json.get(STOP).asArray();
        for(int i=0;i<stopArray.size();i++){
            stops.add(jpti.getStop(stopArray.get(i).asInt()));
            jpti.getStop(stopArray.get(i).asInt()).setStation(this);
        }
    }catch (Exception e){
        e.printStackTrace();
    }
}
 
开发者ID:KameLong,项目名称:AOdia,代码行数:21,代码来源:Station.java

示例10: testGetPortPairGroupId

import com.eclipsesource.json.JsonObject; //导入依赖的package包/类
/**
 * Tests the result of a rest api GET for port pair group id.
 */
@Test
public void testGetPortPairGroupId() {

    final Set<PortPairGroup> portPairGroups = new HashSet<>();
    portPairGroups.add(portPairGroup1);

    expect(portPairGroupService.exists(anyObject())).andReturn(true).anyTimes();
    expect(portPairGroupService.getPortPairGroup(anyObject())).andReturn(portPairGroup1).anyTimes();
    replay(portPairGroupService);

    final WebTarget wt = target();
    final String response = wt.path("port_pair_groups/4512d643-24fc-4fae-af4b-321c5e2eb3d1")
            .request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());
}
 
开发者ID:shlee89,项目名称:athena,代码行数:20,代码来源:PortPairGroupResourceTest.java

示例11: Trip

import com.eclipsesource.json.JsonObject; //导入依赖的package包/类
public Trip(JPTI jpti, JsonObject json){
    this.jpti=jpti;
    try{
        route=jpti.getRoute(json.getInt(ROUTE,0));
            this.traihType=jpti.getTrainType(json.getInt(CLASS,0));
            blockID=json.getInt(BLOCK,0);
            calender=jpti.calendarList.get(json.getInt(CALENDER,0));
        number=json.getString(NUMBER,"");
        name=json.getString(NAME,"");
        direction=json.getInt(DIRECTION,0);
        extraCalendarID=json.getInt(EXTRA_CALENDER,-1);
        JsonArray timeArray=json.get(TIME).asArray();
        for(int i=0;i<timeArray.size();i++){
            Time time=newTime(timeArray.get(i).asObject());
            timeList.put(time.getStation(),time);
        }




    }catch(Exception e){
        e.printStackTrace();
    }
}
 
开发者ID:KameLong,项目名称:AOdia,代码行数:25,代码来源:Trip.java

示例12: testGetDeviceKeyById

import com.eclipsesource.json.JsonObject; //导入依赖的package包/类
/**
 * Tests the result of the REST API GET using a device key identifier.
 */
@Test
public void testGetDeviceKeyById() {
    deviceKeySet.add(deviceKey1);

    expect(mockDeviceKeyService.getDeviceKey(DeviceKeyId.deviceKeyId(deviceKeyId1)))
            .andReturn(deviceKey1)
            .anyTimes();
    replay(mockDeviceKeyService);

    WebTarget wt = target();
    String response = wt.path("keys/" + deviceKeyId1).request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result, matchesDeviceKey(deviceKey1));

    verify(mockDeviceKeyService);
}
 
开发者ID:shlee89,项目名称:athena,代码行数:22,代码来源:DeviceKeyWebResourceTest.java

示例13: testGetFlowClassifierId

import com.eclipsesource.json.JsonObject; //导入依赖的package包/类
/**
 * Tests the result of a rest api GET for flow classifier id.
 */
@Test
public void testGetFlowClassifierId() {

    final Set<FlowClassifier> flowClassifiers = new HashSet<>();
    flowClassifiers.add(flowClassifier1);

    expect(flowClassifierService.exists(anyObject())).andReturn(true).anyTimes();
    expect(flowClassifierService.getFlowClassifier(anyObject())).andReturn(flowClassifier1).anyTimes();
    replay(flowClassifierService);

    final WebTarget wt = target();
    final String response = wt.path("flow_classifiers/4a334cd4-fe9c-4fae-af4b-321c5e2eb051")
                              .request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());
}
 
开发者ID:shlee89,项目名称:athena,代码行数:20,代码来源:FlowClassifierResourceTest.java

示例14: testGetPortPairId

import com.eclipsesource.json.JsonObject; //导入依赖的package包/类
/**
 * Tests the result of a rest api GET for port pair id.
 */
@Test
public void testGetPortPairId() {

    final Set<PortPair> portPairs = new HashSet<>();
    portPairs.add(portPair1);

    expect(portPairService.exists(anyObject())).andReturn(true).anyTimes();
    expect(portPairService.getPortPair(anyObject())).andReturn(portPair1).anyTimes();
    replay(portPairService);

    final WebTarget wt = target();
    final String response = wt.path("port_pairs/78dcd363-fc23-aeb6-f44b-56dc5e2fb3ae")
            .request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());
}
 
开发者ID:shlee89,项目名称:athena,代码行数:20,代码来源:PortPairResourceTest.java

示例15: testSingleLoadGet

import com.eclipsesource.json.JsonObject; //导入依赖的package包/类
/**
 * Tests GET of a single Load statistics object.
 */
@Test
public void testSingleLoadGet() throws UnsupportedEncodingException {
    final WebTarget wt = target();
    final String response = wt.path("statistics/flows/link")
            .queryParam("device", "of:0000000000000001")
            .queryParam("port", "2")
            .request()
            .get(String.class);

    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, notNullValue());

    assertThat(result.names(), hasSize(1));
    assertThat(result.names().get(0), is("loads"));

    final JsonArray jsonLoads = result.get("loads").asArray();
    assertThat(jsonLoads, notNullValue());
    assertThat(jsonLoads.size(), is(1));

    JsonObject load1 = jsonLoads.get(0).asObject();
    checkValues(load1, 111, 222, true, "src3");
}
 
开发者ID:shlee89,项目名称:athena,代码行数:26,代码来源:StatisticsResourceTest.java


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