當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。