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


Java JsonStructure類代碼示例

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


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

示例1: isStatusOk

import javax.json.JsonStructure; //導入依賴的package包/類
/**
    * Says if status is OK
    * @return true if status is OK
    */
   public boolean isStatusOk() {

if (jsonResult == null || jsonResult.isEmpty()) {
    return false;
}

try {
    JsonReader reader = Json.createReader(new StringReader(jsonResult));
    JsonStructure jsonst = reader.read();

    JsonObject object = (JsonObject) jsonst;
    JsonString status = (JsonString) object.get("status");

    if (status != null && status.getString().equals("OK")) {
	return true;
    } else {
	return false;
    }
} catch (Exception e) {
    this.parseException = e;
    invalidJsonStream = true;
    return false;
}

   }
 
開發者ID:kawansoft,項目名稱:aceql-http,代碼行數:30,代碼來源:ResultAnalyzer.java

示例2: addTeams

import javax.json.JsonStructure; //導入依賴的package包/類
/**
 * This method adds teams of the specified page to the teams array.
 *
 * @param arrBuilder specifies the array builder to add the teams into.
 * @param year specifies the optional year, null for all years.
 * @param pageNum specifies the page number.
 * @param verbosity specifies optional verbosity, null for full verbosity.
 * @param statusOut specifies standard output stream for command status, can be null for quiet mode.
 * @return true if successful, false if failed.
 */
private boolean addTeams(
    JsonArrayBuilder arrBuilder, String year, int pageNum, String verbosity, PrintStream statusOut)
{
    String request = "teams/";
    if (year != null) request += year + "/";
    request += pageNum;
    if (verbosity != null) request += "/" + verbosity;

    JsonStructure data = get(request, statusOut, header);
    boolean success;
    if (data != null && data.getValueType() == JsonValue.ValueType.ARRAY && !((JsonArray)data).isEmpty())
    {
        for (JsonValue team: (JsonArray)data)
        {
            arrBuilder.add(team);
        }
        success = true;
    }
    else
    {
        success = false;
    }

    return success;
}
 
開發者ID:trc492,項目名稱:TBAShell,代碼行數:36,代碼來源:TbaApiV3.java

示例3: bodyValue

import javax.json.JsonStructure; //導入依賴的package包/類
/**
 * Returns the value of the body as a structure.
 *
 * @return The value of the body as a structure.
 * @throws RemoteException If the body could not be parsed.
 * @since 2017/12/17
 */
public JsonStructure bodyValue()
	throws RemoteException
{
	Reference<JsonStructure> ref = this._jsonvalue;
	JsonStructure rv;
	
	if (ref == null || null == (rv = ref.get()))
		try
		{
			this._jsonvalue = new WeakReference<>((rv =
				Json.createReader(new StringReader(this.body)).read()));
		}
		catch (JsonException e)
		{
			throw new RemoteException("Failed to parse the body.", e);
		}
	
	return rv;
}
 
開發者ID:iopipe,項目名稱:iopipe-java-core,代碼行數:27,代碼來源:RemoteResult.java

示例4: bodyValue

import javax.json.JsonStructure; //導入依賴的package包/類
/**
 * Returns the value of the body as a structure.
 *
 * @return The value of the body as a structure.
 * @throws RemoteException If the JSON is not valid.
 * @since 2017/12/17
 */
public JsonStructure bodyValue()
	throws RemoteException
{
	Reference<JsonStructure> ref = this._jsonvalue;
	JsonStructure rv;
	
	if (ref == null || null == (rv = ref.get()))
		try
		{
			this._jsonvalue = new WeakReference<>((rv =
				Json.createReader(new StringReader(this.body)).read()));
		}
		catch (JsonException e)
		{
			throw new RemoteException("Failed to parse the body.", e);
		}
	
	return rv;
}
 
開發者ID:iopipe,項目名稱:iopipe-java-core,代碼行數:27,代碼來源:RemoteRequest.java

示例5: unbox

import javax.json.JsonStructure; //導入依賴的package包/類
public static Object unbox(JsonValue value, Function<JsonStructure, Object> convert) throws JsonException {
    switch (value.getValueType()) {
        case ARRAY:
        case OBJECT:
            return convert.apply((JsonStructure) value);
        case FALSE:
            return Boolean.FALSE;
        case TRUE:
            return Boolean.TRUE;
        case NULL:
            return null;
        case NUMBER:
            JsonNumber number = (JsonNumber) value;
            return number.isIntegral() ? number.longValue() : number.doubleValue();
        case STRING:
            return ((JsonString) value).getString();
        default:
            throw new JsonException("Unknow value type");
    }
}
 
開發者ID:apache,項目名稱:sling-org-apache-sling-launchpad-integration-tests,代碼行數:21,代碼來源:JsonUtil.java

示例6: formatBody

import javax.json.JsonStructure; //導入依賴的package包/類
private String formatBody(String contentType, String body) {
	if (body != null && contentType != null) {
		if (contentType.startsWith("application/json")) {
			try {
				JsonStructure json = Json.createReader(new StringReader(body)).read();
				StringWriter w = new StringWriter();
				HashMap<String, Object> p = new HashMap<>();
				p.put(JsonGenerator.PRETTY_PRINTING, true);
				Json.createWriterFactory(p).createWriter(w).write(json);
				return w.toString();
			} catch (JsonException ex) {
				return body;
			}
		} else {
			return body;
		}
	} else {
		return null;
	}
}
 
開發者ID:RUB-NDS,項目名稱:PrOfESSOS,代碼行數:21,代碼來源:TestStepLogger.java

示例7: enablePlugin

import javax.json.JsonStructure; //導入依賴的package包/類
@POST
@Path("{id}/enable")
public JsonStructure enablePlugin(@PathParam("id") String id,
                                  @DefaultValue("0") @QueryParam("timeout") int timeout) {

    WebTarget target = resource().path("plugins").path(id).path("enable").queryParam("timeout", timeout);

    Response response = postResponse(target);
    String entity = response.readEntity(String.class);
    response.close();

    JsonStructure structure;
    if (entity.isEmpty()) {
        structure = Json.createObjectBuilder().add("message", id + " plugin enabled.").build();
    } else {
        structure = Json.createReader(new StringReader(entity)).read();
    }
    return structure;
}
 
開發者ID:ozlerhakan,項目名稱:rapid,代碼行數:20,代碼來源:Plugin.java

示例8: disablePlugin

import javax.json.JsonStructure; //導入依賴的package包/類
@POST
@Path("{id}/disable")
public JsonStructure disablePlugin(@PathParam("id") String id) {

    WebTarget target = resource().path("plugins").path(id).path("disable");

    Response response = postResponse(target);
    String entity = response.readEntity(String.class);
    response.close();

    JsonStructure structure;
    if (entity.isEmpty()) {
        structure = Json.createObjectBuilder().add("message", id + " plugin disabled.").build();
    } else {
        structure = Json.createReader(new StringReader(entity)).read();
    }
    return structure;
}
 
開發者ID:ozlerhakan,項目名稱:rapid,代碼行數:19,代碼來源:Plugin.java

示例9: pullPlugin

import javax.json.JsonStructure; //導入依賴的package包/類
@POST
@Path("pull")
public JsonStructure pullPlugin(@QueryParam("remote") String remote,
                                @QueryParam("name") String name,
                                JsonStructure content) {

    WebTarget target = resource().path("plugins").path("pull");

    if (Objects.nonNull(remote))
        target = target.queryParam("remote", remote);
    if (Objects.nonNull(name))
        target = target.queryParam("name", name);

    Response response = postResponse(target, content);
    String entity = response.readEntity(String.class);
    response.close();

    JsonStructure result;
    if (entity.isEmpty()) {
        result = Json.createObjectBuilder().add("message", "plugin pulled.").build();
    } else {
        result = Json.createReader(new StringReader(entity)).read();
    }
    return result;
}
 
開發者ID:ozlerhakan,項目名稱:rapid,代碼行數:26,代碼來源:Plugin.java

示例10: pushPlugin

import javax.json.JsonStructure; //導入依賴的package包/類
@POST
@Path("{id}/push")
public JsonStructure pushPlugin(@PathParam("id") String id) {

    WebTarget target = resource().path("plugins").path(id).path("push");

    Response response = postResponse(target);
    String entity = response.readEntity(String.class);
    response.close();

    JsonStructure result;
    if (entity.isEmpty()) {
        result = Json.createObjectBuilder().add("message", id + " plugin pushed.").build();
    } else {
        result = Json.createReader(new StringReader(entity)).read();
    }
    return result;
}
 
開發者ID:ozlerhakan,項目名稱:rapid,代碼行數:19,代碼來源:Plugin.java

示例11: upgradePlugin

import javax.json.JsonStructure; //導入依賴的package包/類
@POST
@Path("{id}/upgrade")
public JsonStructure upgradePlugin(@PathParam("id") String id,
                                   @QueryParam("remote") String remote,
                                   JsonStructure content) {

    WebTarget target = resource().path("plugins").path(id).path("upgrade");

    if (Objects.nonNull(remote))
        target = target.queryParam("remote", remote);

    Response response = postResponse(target, content);
    String entity = response.readEntity(String.class);
    response.close();

    JsonStructure result;
    if (entity.isEmpty()) {
        result = Json.createObjectBuilder().add("message", id + " plugin upgraded.").build();
    } else {
        result = Json.createReader(new StringReader(entity)).read();
    }
    return result;
}
 
開發者ID:ozlerhakan,項目名稱:rapid,代碼行數:24,代碼來源:Plugin.java

示例12: settingPlugin

import javax.json.JsonStructure; //導入依賴的package包/類
@POST
@Path("{id}/set")
public JsonStructure settingPlugin(@PathParam("id") String id,
                                   JsonStructure content) {

    WebTarget target = resource().path("plugins").path(id).path("set");

    Response response = postResponse(target, content);
    String entity = response.readEntity(String.class);
    response.close();

    JsonStructure result;
    if (entity.isEmpty()) {
        result = Json.createObjectBuilder().add("message", id + " plugin configuration set.").build();
    } else {
        result = Json.createReader(new StringReader(entity)).read();
    }
    return result;
}
 
開發者ID:ozlerhakan,項目名稱:rapid,代碼行數:20,代碼來源:Plugin.java

示例13: toString

import javax.json.JsonStructure; //導入依賴的package包/類
public static String toString(final JsonStructure json) {

		final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

		final JsonWriter jsonWriter = getPrettyJsonWriterFactory()
				.createWriter(outputStream, Charset.forName("UTF-8"));

		jsonWriter.write(json);
		jsonWriter.close();

		String jsonString;
		try {
			jsonString = new String(outputStream.toByteArray(), "UTF8");
		} catch (UnsupportedEncodingException e) {
			throw new RuntimeException(e);
		}

		return jsonString;
	}
 
開發者ID:biggis-project,項目名稱:path-optimizer,代碼行數:20,代碼來源:JsonUtils.java

示例14: testBson

import javax.json.JsonStructure; //導入依賴的package包/類
@Test
public void testBson () throws IOException
{
	BasicConfigurator.configure ();
	String f = "../tests/data/data1.bson";
	File file = new File (f.replace ('/', File.separatorChar));

	JsonPathProvider provider = new JsonPathProvider ();

	Configuration pathConfig = Configuration.defaultConfiguration ().jsonProvider (provider);
	JsonPath path = JsonPath.compile ("$..A");

	JsonProvider p = new CookJsonProvider ();
	HashMap<String, Object> readConfig = new HashMap<String, Object> ();
	readConfig.put (CookJsonProvider.FORMAT, CookJsonProvider.FORMAT_BSON);
	readConfig.put (CookJsonProvider.ROOT_AS_ARRAY, Boolean.TRUE);
	JsonReaderFactory rf = p.createReaderFactory (readConfig);
	JsonReader reader = rf.createReader (new FileInputStream (file));
	JsonStructure obj = reader.read ();
	reader.close ();

	JsonValue value = path.read (obj, pathConfig);

	Assert.assertEquals ("[1,3,5,7]", provider.toJson (value));
}
 
開發者ID:coconut2015,項目名稱:cookjson,代碼行數:26,代碼來源:JsonPathProviderTest.java

示例15: deserializeMap

import javax.json.JsonStructure; //導入依賴的package包/類
/**
 * Map deserialization.
 *
 * {@literal JsonObject}s are deserialized to {@literal Map<String, ?>}.
 * {@literal JsonArray}s of key/value {@literal JsonObject}s are deserialized to {@literal Map<?, ?>}.
 */
private Map<?, ?> deserializeMap( ModuleDescriptor module, MapType mapType, JsonStructure json )
{
    if( json.getValueType() == JsonValue.ValueType.OBJECT )
    {
        JsonObject object = (JsonObject) json;
        return object.entrySet().stream()
                     .map( entry -> new AbstractMap.SimpleImmutableEntry<>(
                         entry.getKey(),
                         doDeserialize( module, mapType.valueType(), entry.getValue() ) ) )
                     .collect( toMapWithNullValues( LinkedHashMap::new ) );
    }
    if( json.getValueType() == JsonValue.ValueType.ARRAY )
    {
        JsonArray array = (JsonArray) json;
        return array.stream()
                    .map( JsonObject.class::cast )
                    .map( entry -> new AbstractMap.SimpleImmutableEntry<>(
                        doDeserialize( module, mapType.keyType(), entry.get( "key" ) ),
                        doDeserialize( module, mapType.valueType(), entry.get( "value" ) )
                    ) )
                    .collect( toMapWithNullValues( LinkedHashMap::new ) );
    }
    throw new SerializationException( "Don't know how to deserialize " + mapType + " from " + json );
}
 
開發者ID:apache,項目名稱:polygene-java,代碼行數:31,代碼來源:JavaxJsonDeserializer.java


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