當前位置: 首頁>>代碼示例>>Java>>正文


Java Json類代碼示例

本文整理匯總了Java中com.eclipsesource.json.Json的典型用法代碼示例。如果您正苦於以下問題:Java Json類的具體用法?Java Json怎麽用?Java Json使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Json類屬於com.eclipsesource.json包,在下文中一共展示了Json類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: setup

import com.eclipsesource.json.Json; //導入依賴的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

示例2: testSingleHostByMacAndVlanFetch

import com.eclipsesource.json.Json; //導入依賴的package包/類
/**
 * Tests fetch of one host by mac and vlan.
 */
@Test
public void testSingleHostByMacAndVlanFetch() {
    final ProviderId pid = new ProviderId("of", "foo");
    final MacAddress mac1 = MacAddress.valueOf("00:00:11:00:00:01");
    final Set<IpAddress> ips1 = ImmutableSet.of(IpAddress.valueOf("1111:1111:1111:1::"));
    final Host host1 =
            new DefaultHost(pid, HostId.hostId(mac1), valueOf(1), vlanId((short) 1),
                    new HostLocation(DeviceId.deviceId("1"), portNumber(11), 1),
                    ips1);

    hosts.add(host1);

    expect(mockHostService.getHost(HostId.hostId("00:00:11:00:00:01/1")))
            .andReturn(host1)
            .anyTimes();
    replay(mockHostService);

    WebTarget wt = target();
    String response = wt.path("hosts/00:00:11:00:00:01/1").request().get(String.class);
    final JsonObject result = Json.parse(response).asObject();
    assertThat(result, matchesHost(host1));
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:26,代碼來源:HostResourceTest.java

示例3: load

import com.eclipsesource.json.Json; //導入依賴的package包/類
private static Multimap<JsonStage, JsonValue> load(Map<String, FileHandle> map) throws IOException {
 try {
  Multimap<JsonStage, JsonValue> m = new Multimap<JsonStage, JsonValue>();
  for (Map.Entry<String, FileHandle> entry : map.entrySet()) {
    JsonStage stage = null;
    if (entry.getKey().startsWith("block")) {
      stage = JsonStage.BLOCK;
    } else if (entry.getKey().startsWith("item")) {
      stage = JsonStage.ITEM;
    } else if (entry.getKey().startsWith("recipe")) {
      stage = JsonStage.RECIPE;
    } else {
      throw new CubesException("Invalid json file path \"" + entry.getKey() + "\"");
    }

    Reader reader = entry.getValue().reader();
  
      m.put(stage, Json.parse(reader));
    } 
  }finally {
      reader.close();
    }
  return m;
}
 
開發者ID:RedTroop,項目名稱:Cubes_2,代碼行數:25,代碼來源:JsonLoader.java

示例4: read

import com.eclipsesource.json.Json; //導入依賴的package包/類
public static boolean read() {
	FileHandle fileHandle = Compatibility.get().getBaseFolder().child("settings.json");

	try {
		Reader reader = fileHandle.reader();
		JsonObject json = Json.parse(reader).asObject();
		reader.close();

		for (Member member : json) {
			Setting setting = set.settings.get(member.getName());
			setting.readJson(member.getValue());
		}

		return true;
	} catch (Exception e) {
		Log.error("Failed to read settings", e);
		fileHandle.delete();
		return false;
	}
}
 
開發者ID:RedTroop,項目名稱:Cubes_2,代碼行數:21,代碼來源:Settings.java

示例5: executeCommandAndGetJsonValue

import com.eclipsesource.json.Json; //導入依賴的package包/類
private JsonValue executeCommandAndGetJsonValue(String command1, String command2, String command3)
	throws WalletCallException, IOException, InterruptedException
{
	String strResponse = this.executeCommandAndGetSingleStringResponse(command1, command2, command3);

	JsonValue response = null;
	try
	{
	  	response = Json.parse(strResponse);
	} catch (ParseException pe)
	{
	  	throw new WalletCallException(strResponse + "\n" + pe.getMessage() + "\n", pe);
	}

	return response;
}
 
開發者ID:ZencashOfficial,項目名稱:zencash-swing-wallet-ui,代碼行數:17,代碼來源:ZCashClientCaller.java

示例6: doPost

import com.eclipsesource.json.Json; //導入依賴的package包/類
@Override
public ModelAndView doPost(IHTTPSession session) {
	JsonValue request = Json.parse(WebServer.getRequestBody(session));
	if (!request.isObject()) {
		return new BadRequest("expected object");
	}
	ValidationResult errors = new ValidationResult();
	String username = ((JsonObject) request).getString("username", null);
	if (username == null || username.trim().length() == 0) {
		errors.put("username", "Cannot be empty");
	}
	if (!errors.isEmpty()) {
		LOG.info("unable to save: " + errors);
		return new BadRequest(errors);
	}
	auth.resetPassword(username);
	return new Success();
}
 
開發者ID:dernasherbrezon,項目名稱:r2cloud,代碼行數:19,代碼來源:Restore.java

示例7: doGet

import com.eclipsesource.json.Json; //導入依賴的package包/類
@Override
public ModelAndView doGet(IHTTPSession session) {
	ModelAndView result = new ModelAndView();
	JsonArray array = (JsonArray) Json.array();
	for (Airplane cur : dao.getAirplanes()) {
		JsonArray positions = (JsonArray) Json.array();
		if (cur.getPositions() != null) {
			for (Position curPosition : cur.getPositions()) {
				positions.add(Json.object().add("lng", curPosition.getLongitude()).add("lat", curPosition.getLatitude()));
			}
		}
		array.add(Json.object().add("icao24", cur.getIcao24()).add("positions", positions));
	}
	result.setData(array.toString());
	return result;
}
 
開發者ID:dernasherbrezon,項目名稱:r2cloud,代碼行數:17,代碼來源:ADSB.java

示例8: doPost

import com.eclipsesource.json.Json; //導入依賴的package包/類
@Override
public ModelAndView doPost(IHTTPSession session) {
	JsonValue request = Json.parse(WebServer.getRequestBody(session));
	if (!request.isObject()) {
		return new BadRequest("expected object");
	}
	ValidationResult errors = new ValidationResult();
	Double lat = WebServer.getDouble(request, "lat");
	Double lon = WebServer.getDouble(request, "lng");
	if (lat == null) {
		errors.put("lat", "Cannot be empty");
	}
	if (lon == null) {
		errors.put("lng", "Cannot be empty");
	}
	if (!errors.isEmpty()) {
		LOG.info("unable to save: " + errors);
		return new BadRequest(errors);
	}
	autoUpdate.setEnabled(WebServer.getBoolean(request, "autoUpdate"));
	config.setProperty("locaiton.lat", String.valueOf(lat));
	config.setProperty("locaiton.lon", String.valueOf(lon));
	config.update();
	return new Success();
}
 
開發者ID:dernasherbrezon,項目名稱:r2cloud,代碼行數:26,代碼來源:General.java

示例9: testGetPortPairId

import com.eclipsesource.json.Json; //導入依賴的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

示例10: load

import com.eclipsesource.json.Json; //導入依賴的package包/類
private static Multimap<JsonStage, JsonValue> load(Map<String, FileHandle> map) throws IOException {
  Multimap<JsonStage, JsonValue> m = new Multimap<JsonStage, JsonValue>();
  for (Map.Entry<String, FileHandle> entry : map.entrySet()) {
    JsonStage stage = null;
    if (entry.getKey().startsWith("block")) {
      stage = JsonStage.BLOCK;
    } else if (entry.getKey().startsWith("item")) {
      stage = JsonStage.ITEM;
    } else if (entry.getKey().startsWith("recipe")) {
      stage = JsonStage.RECIPE;
    } else {
      throw new CubesException("Invalid json file path \"" + entry.getKey() + "\"");
    }

    Reader reader = entry.getValue().reader();
    try {
      m.put(stage, Json.parse(reader));
    } finally {
      reader.close();
    }
  }
  return m;
}
 
開發者ID:RedTroop,項目名稱:Cubes,代碼行數:24,代碼來源:JsonLoader.java

示例11: read

import com.eclipsesource.json.Json; //導入依賴的package包/類
public static boolean read() {
  FileHandle fileHandle = Compatibility.get().getBaseFolder().child("settings.json");
  
  try {
    Reader reader = fileHandle.reader();
    JsonObject json = Json.parse(reader).asObject();
    reader.close();

    for (Member member : json) {
      Setting setting = settings.get(member.getName());
      setting.readJson(member.getValue());
    }
    
    return true;
  } catch (Exception e) {
    Log.error("Failed to read settings", e);
    fileHandle.delete();
    return false;
  }
}
 
開發者ID:RedTroop,項目名稱:Cubes,代碼行數:21,代碼來源:Settings.java

示例12: testMetersPopulatedArray

import com.eclipsesource.json.Json; //導入依賴的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

示例13: testMeterSingleDevice

import com.eclipsesource.json.Json; //導入依賴的package包/類
/**
 * Tests the results of a rest api GET for a device.
 */
@Test
public void testMeterSingleDevice() {
    setupMockMeters();

    final Set<Meter> meters1 = new HashSet<>();
    meters1.add(meter1);
    meters1.add(meter2);

    expect(mockMeterService.getMeters(anyObject())).andReturn(meters1).anyTimes();
    replay(mockMeterService);
    replay(mockDeviceService);

    final WebTarget wt = target();
    final String response = wt.path("meters/" + deviceId1.toString()).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));
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:28,代碼來源:MetersResourceTest.java

示例14: testMeterSingleDeviceWithId

import com.eclipsesource.json.Json; //導入依賴的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

示例15: read

import com.eclipsesource.json.Json; //導入依賴的package包/類
@Override
public Bmv2DeviceContext read(Kryo kryo, Input input, Class<Bmv2DeviceContext> type) {
    String jsonStr = kryo.readObject(input, String.class);
    String interpreterClassName = kryo.readObject(input, String.class);
    Bmv2Configuration configuration = parse(Json.parse(jsonStr).asObject());
    ClassLoader loader = interpreterClassLoaders.get(interpreterClassName);
    if (loader == null) {
        throw new IllegalStateException("No class loader registered for interpreter: " + interpreterClassName);
    }
    try {
        Bmv2Interpreter interpreter = (Bmv2Interpreter) loader.loadClass(interpreterClassName).newInstance();
        return new Bmv2DeviceContext(configuration, interpreter);
    } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
        throw new RuntimeException("Unable to load interpreter class", e);
    }
}
 
開發者ID:shlee89,項目名稱:athena,代碼行數:17,代碼來源:Bmv2DeviceContextServiceImpl.java


注:本文中的com.eclipsesource.json.Json類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。