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


Java JSONValue类代码示例

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


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

示例1: process

import net.minidev.json.JSONValue; //导入依赖的package包/类
@Override
public void process(final ExecutionContext executionContext, final TemplateContentModelImpl contentModel)
        throws ProcessException {
    try {
        SlingHttpServletRequest request = (SlingHttpServletRequest) executionContext.get(SLING_HTTP_REQUEST);
        Configuration config = configurationProvider.getFor(request.getResource().getResourceType());
        Collection<String> propsWithJSONValues = config.asStrings(XK_DESERIALIZE_JSON_PROPS_CP, Mode.MERGE);

        for(String propName : propsWithJSONValues) {
            if(contentModel.has(propName)) {
                String jsonString = contentModel.getAsString(propName);
                if(JSONValue.isValidJson(jsonString)) {
                    Object value = JSONValue.parse(jsonString);
                    contentModel.set(propName, value);
                }
            }
        }
    } catch (Exception e) {
        throw new ProcessException(e);
    }
}
 
开发者ID:DantaFramework,项目名称:AEM,代码行数:22,代码来源:DeserializeJSONPropertyValuesContextProcessor.java

示例2: process

import net.minidev.json.JSONValue; //导入依赖的package包/类
@Override
public void process(final ExecutionContext executionContext, TemplateContentModelImpl contentModel)
        throws ProcessException {
    try {
        Resource resource = (Resource) executionContext.get(JAHIA_RESOURCE);
        Configuration configuration = configurationProvider.getFor(resource);
        Collection<String> propsWithJSONValues = configuration.asStrings(XK_DESERIALIZE_JSON_PROPS_CP, Mode.MERGE);

        for(String propName : propsWithJSONValues) {
            if(contentModel.has(propName)) {
                String jsonString = contentModel.getAsString(propName);
                if(JSONValue.isValidJson(jsonString)) {
                    Object value = JSONValue.parse(jsonString);
                    contentModel.set(propName, value);
                }
            }
        }
    } catch (Exception e) {
        throw new ProcessException(e);
    }
}
 
开发者ID:DantaFramework,项目名称:JahiaDF,代码行数:22,代码来源:DeserializeJSONPropertyValuesContextProcessor.java

示例3: map

import net.minidev.json.JSONValue; //导入依赖的package包/类
@Override
public <T> T map(Object source, Class<T> targetType, Configuration configuration) {
    if(source == null){
        return null;
    }
    if (targetType.isAssignableFrom(source.getClass())) {
        return (T) source;
    }
    try {
        if(!configuration.jsonProvider().isMap(source) && !configuration.jsonProvider().isArray(source)){
            return factory.call().getMapper(targetType).convert(source);
        }
        String s = configuration.jsonProvider().toJson(source);
        return (T) JSONValue.parse(s, targetType);
    } catch (Exception e) {
        throw new MappingException(e);
    }

}
 
开发者ID:osswangxining,项目名称:another-rule-based-analytics-on-spark,代码行数:20,代码来源:JsonSmartMappingProvider.java

示例4: JafigJSON

import net.minidev.json.JSONValue; //导入依赖的package包/类
public JafigJSON(Object[] parameters) {
    super(parameters);
    if (parameters.length != 1) {
        throw new InvalidParameterException("File must be provided");
    }
    File file;
    if (parameters[0] instanceof String) {
        file = new File((String) parameters[0]);
    } else if (parameters[0] instanceof File) {
        file = (File) parameters[0];
    } else {
        throw new InvalidParameterException("File must be provided as a String, or File");
    }
    this.file = file;
    if (file.exists()) {
        try {
            FileInputStream inputStream = new FileInputStream(file);
            this.data = (JSONObject) JSONValue.parse(inputStream);
            inputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:PaulBGD,项目名称:Jafig,代码行数:25,代码来源:JafigJSON.java

示例5: testJSONEventLayoutHasUserFieldsFromProps

import net.minidev.json.JSONValue; //导入依赖的package包/类
@Test
public void testJSONEventLayoutHasUserFieldsFromProps() {
    System.setProperty(JSONEventLayoutV1.ADDITIONAL_DATA_PROPERTY, userFieldsSingleProperty);
    logger.info("Test9: JSON Event Layout Has User Fields From Props");
    String message = appender.getMessages()[0];

    Assert.assertTrue("Event is not valid JSON", JSONValue.isValidJsonStrict(message));

    Object obj = JSONValue.parse(message);
    JSONObject jsonObject = (JSONObject) obj;

    Assert.assertTrue("Event does not contain field 'field1'" , jsonObject.containsKey("field1"));
    Assert.assertEquals("Event does not contain value 'value1'", "propval1", jsonObject.get("field1"));

    System.clearProperty(JSONEventLayoutV1.ADDITIONAL_DATA_PROPERTY);
}
 
开发者ID:juise,项目名称:logstash-logback-layout,代码行数:17,代码来源:JSONEventLayoutV1Test.java

示例6: testJSONEventLayoutHasUserFieldsFromConfig

import net.minidev.json.JSONValue; //导入依赖的package包/类
@Test
public void testJSONEventLayoutHasUserFieldsFromConfig() {
    JSONEventLayoutV1 layout = (JSONEventLayoutV1) appender.getLayout();
    layout.setUserFields(userFieldsSingle);

    logger.info("Test10: JSON Event Layout Has User Fields From Config");
    String message = appender.getMessages()[0];

    Assert.assertTrue("Event is not valid JSON", JSONValue.isValidJsonStrict(message));

    Object obj = JSONValue.parse(message);
    JSONObject jsonObject = (JSONObject) obj;

    Assert.assertTrue("Event does not contain field 'field1'" , jsonObject.containsKey("field1"));
    Assert.assertEquals("Event does not contain value 'value1'", "value1", jsonObject.get("field1"));
}
 
开发者ID:juise,项目名称:logstash-logback-layout,代码行数:17,代码来源:JSONEventLayoutV1Test.java

示例7: testJSONEventLayoutUserFieldsMulti

import net.minidev.json.JSONValue; //导入依赖的package包/类
@Test
public void testJSONEventLayoutUserFieldsMulti() {
    JSONEventLayoutV1 layout = (JSONEventLayoutV1) appender.getLayout();
    layout.setUserFields(userFieldsMulti);

    logger.info("Test11: JSON Event Layout Has User Fields Multi");
    String message = appender.getMessages()[0];

    Assert.assertTrue("Event is not valid JSON", JSONValue.isValidJsonStrict(message));

    Object obj = JSONValue.parse(message);
    JSONObject jsonObject = (JSONObject) obj;

    Assert.assertTrue("Event does not contain field 'field2'" , jsonObject.containsKey("field2"));
    Assert.assertEquals("Event does not contain value 'value2'", "value2", jsonObject.get("field2"));
    Assert.assertTrue("Event does not contain field 'field3'" , jsonObject.containsKey("field3"));
    Assert.assertEquals("Event does not contain value 'value3'", "value3", jsonObject.get("field3"));
}
 
开发者ID:juise,项目名称:logstash-logback-layout,代码行数:19,代码来源:JSONEventLayoutV1Test.java

示例8: getActiveUserInfo

import net.minidev.json.JSONValue; //导入依赖的package包/类
private JSONObject getActiveUserInfo() throws ParseException {

		if(this.getActiveAgent() instanceof UserAgent){
			UserAgent me = (UserAgent) this.getActiveAgent();
			JSONObject o;

			if(me.getUserData() != null){
				System.err.println(me.getUserData());
				o = (JSONObject) JSONValue.parseWithException((String) me.getUserData());
			} else {
				o = new JSONObject();

				if(getActiveNode().getAnonymous().getId() == getActiveAgent().getId()){
					o.put("sub","anonymous");		
				} else {

					String md5ide = new String(""+me.getId());
					o.put("sub", md5ide);
				}
			}
			return o;

		} else {
			return new JSONObject();
		}
	}
 
开发者ID:rwth-acis,项目名称:LAS2peer-AnnotationService,代码行数:27,代码来源:AnnotationsService.java

示例9: modifyAnnotationContextArray

import net.minidev.json.JSONValue; //导入依赖的package包/类
/**
 * Remove useless information about annotationContexts
 * @param annotationContextArray annotationContextArray from ArangoDB
 * @return modified array without good-for-nothing information
 */
private JSONArray modifyAnnotationContextArray(JSONArray annotationContextArray){
	JSONArray modified = new JSONArray();
	
	for (Object newJS:annotationContextArray){
		//JSONObject newJS = (JSONObject) JSONValue.parse(edge);
			JSONObject newAnnotationContext = (JSONObject) JSONValue.parse(newJS.toString());
			newAnnotationContext.remove(new String("_id"));
			newAnnotationContext.remove(new String("_key"));
			newAnnotationContext.remove(new String("_rev"));
			newAnnotationContext.remove(new String("_from"));
			newAnnotationContext.remove(new String("_to"));
			modified.add(newAnnotationContext);
		}
	return modified;
	
}
 
开发者ID:rwth-acis,项目名称:LAS2peer-AnnotationService,代码行数:22,代码来源:AnnotationsService.java

示例10: writeJSONString

import net.minidev.json.JSONValue; //导入依赖的package包/类
public <E extends Iterable<? extends Object>> void writeJSONString(E list, Appendable out, JSONStyle compression) throws IOException {
	boolean first = true;
	compression.arrayStart(out);
	for (Object value : list) {
		if (first) {
			first = false;
			compression.arrayfirstObject(out);
		} else {
			compression.arrayNextElm(out);
		}
		if (value == null)
			out.append("null");
		else
			JSONValue.writeJSONString(value, out, compression);
		compression.arrayObjectEnd(out);
	}
	compression.arrayStop(out);
}
 
开发者ID:netplex,项目名称:json-smart-v1,代码行数:19,代码来源:JsonWriter.java

示例11: doCheck

import net.minidev.json.JSONValue; //导入依赖的package包/类
private void doCheck() throws IOException {
    URLConnection urlConnection = url.openConnection();
    urlConnection.setConnectTimeout(3000); // curse can be slow, this should be good though
    urlConnection.setDoOutput(true);
    InputStream inputStream = urlConnection.getInputStream();
    JSONArray jsonArray = (JSONArray) JSONValue.parse(inputStream);
    inputStream.close();

    // process the result
    if (jsonArray.size() == 0) {
        BGDCore.getLogging().warning("Failed to update plugin \"" + plugin.getName() + "\" due to invalid id '" + id + "!");
        return;
    }
    JSONObject updateData = (JSONObject) jsonArray.get(jsonArray.size() - 1);
    String remoteVersion = (String) updateData.get("name");
    if (remoteVersion.lastIndexOf("v") < remoteVersion.length() - 7) {
        BGDCore.getLogging().warning("Invalid remote version '" + updateData.get("name") + "' (" + remoteVersion.lastIndexOf("v") + ") for plugin \"" + plugin.getName() + "\"!");
        return;
    }
    String hostVersion = remoteVersion.substring(remoteVersion.lastIndexOf("v") + 1);
    if (hostVersion.equalsIgnoreCase(plugin.getDescription().getVersion())) {
        // same version! no update needed
        return;
    }
    latestFileURL = new URL((String) updateData.get("downloadUrl"));
}
 
开发者ID:BurnGames,项目名称:BGDCore,代码行数:27,代码来源:PluginUpdater.java

示例12: loadData

import net.minidev.json.JSONValue; //导入依赖的package包/类
/**
 * Loads a new BlockData using the id and some sort of object
 *
 * @param id   the block id
 * @param data either a JSON string, JSON object, or short
 * @return new BlockData
 */
public static BlockData loadData(int id, Object data) {
    if (data instanceof String) {
        String stringedData = (String) data;
        if (JSONValue.isValidJson(stringedData)) {
            data = JSONValue.parse(stringedData);
        }
    }
    if (data instanceof JSONObject) {
        // load complex data!
        return new ComplexBlockData(id, (JSONObject) data);
    } else {
        // normal block, not an issue
        return new SimpleBlockData(id, Short.valueOf(data.toString()));
    }
}
 
开发者ID:BurnGames,项目名称:BGDCore,代码行数:23,代码来源:BlockData.java

示例13: testCall

import net.minidev.json.JSONValue; //导入依赖的package包/类
public void testCall(final String path, final String expectedResponse, Charset charset, String userAgent, String user, String password, int expect) throws Exception {
        TestHttpClient client = new TestHttpClient();
        try {
            String url = DefaultServer.getDefaultServerURL() + "/dumprunwarrequest?userpath=" + path;
            HttpGet get = new HttpGet(url);
            get = new HttpGet(url);
            get.addHeader(Headers.USER_AGENT_STRING, userAgent);
            get.addHeader(AUTHORIZATION.toString(), BASIC + " " + FlexBase64.encodeString((user + ":" + password).getBytes(charset), false));
            HttpResponse result = client.execute(get);
            assertEquals(expect, result.getStatusLine().getStatusCode());

            final String response = HttpClientUtils.readResponse(result);
            System.out.println(response);
            if(expect == 200) {
                JSONObject responseData = (JSONObject) JSONValue.parse(response);
                String authType = responseData.get(path)!=null?responseData.get(path).toString():"";
                String authHeader = ((JSONObject) responseData.get("headers")).get(Headers.AUTHORIZATION_STRING).toString();
                assertEquals(expectedResponse, authType);
            }
        } finally {
            client.getConnectionManager().shutdown();
        }
}
 
开发者ID:cfmlprojects,项目名称:runwar,代码行数:24,代码来源:BasicAuthTest.java

示例14: testForwardFor

import net.minidev.json.JSONValue; //导入依赖的package包/类
@Test
public void testForwardFor() throws IOException {

    String port = "8088";
    String forwardFor = "some.domain.forwarded";
    Assert.assertTrue(DefaultServer.getServerOptions().isProxyPeerAddressEnabled());
    final TestHttpClient client = new TestHttpClient();
    try {
        HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/dumprunwarrequest");
        get.addHeader(Headers.X_FORWARDED_FOR_STRING, forwardFor);
        HttpResponse result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        JSONObject responseData = (JSONObject) JSONValue.parse(HttpClientUtils.readResponse(result));
        Assert.assertEquals(forwardFor + ":0", responseData.get("remoteAddr"));
        Assert.assertEquals(forwardFor, responseData.get("remoteHost"));
        Assert.assertEquals("localhost:" + port, responseData.get("host"));
        Assert.assertEquals(forwardFor,
                ((JSONObject) responseData.get("headers")).get(Headers.X_FORWARDED_FOR_STRING));
    } finally {
        client.getConnectionManager().shutdown();
    }
}
 
开发者ID:cfmlprojects,项目名称:runwar,代码行数:23,代码来源:ProxyPeerAddressTest.java

示例15: testForwardForHostPort

import net.minidev.json.JSONValue; //导入依赖的package包/类
@Test
public void testForwardForHostPort() throws IOException {
    
    String forwardFor = "localhost";
    String forwardPort = "8765";
    Assert.assertTrue(DefaultServer.getServerOptions().isProxyPeerAddressEnabled());
    final TestHttpClient client = new TestHttpClient();
    try {
        HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/dumprunwarrequest");
        get.addHeader(Headers.X_FORWARDED_FOR_STRING, forwardFor);
        get.addHeader(Headers.X_FORWARDED_HOST_STRING, forwardFor);
        get.addHeader(Headers.X_FORWARDED_PORT_STRING, forwardPort);
        HttpResponse result = client.execute(get);
        Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode());
        JSONObject responseData = (JSONObject) JSONValue.parse(HttpClientUtils.readResponse(result));
        Assert.assertEquals(forwardFor + ":" + forwardPort, responseData.get("host"));
        Assert.assertEquals(forwardFor, responseData.get("remoteHost"));
        Assert.assertEquals(forwardFor,
                ((JSONObject) responseData.get("headers")).get(Headers.X_FORWARDED_FOR_STRING));
    } finally {
        client.getConnectionManager().shutdown();
    }
}
 
开发者ID:cfmlprojects,项目名称:runwar,代码行数:24,代码来源:ProxyPeerAddressTest.java


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