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


Java JSONSerializer类代码示例

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


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

示例1: extractErrorMessage

import net.sf.json.JSONSerializer; //导入依赖的package包/类
@Override
protected String extractErrorMessage(String response) {
    if (response != null && !response.isEmpty()) {
        try {
            JSON jsonResponse = JSONSerializer.toJSON(response, new JsonConfig());
            if (jsonResponse instanceof JSONObject) {
                JSONObject object = (JSONObject) jsonResponse;
                JSONObject errorObj = object.getJSONObject("error");
                if (errorObj.containsKey("message")) {
                    return errorObj.getString("message");
                }
            }
        } catch (JSONException ex) {
            log.debug("Cannot parse JSON error response: " + response);
        }
    }
    return response;
}
 
开发者ID:Blazemeter,项目名称:jmeter-bzm-plugins,代码行数:19,代码来源:BlazeMeterHttpUtils.java

示例2: jsonToLimitViolation

import net.sf.json.JSONSerializer; //导入依赖的package包/类
public static LimitViolation jsonToLimitViolation(String json, Network network) {
    JSONObject jsonObj = (JSONObject) JSONSerializer.toJSON(json);
    Map<String, String> limitViolation = (Map<String, String>) JSONObject.toBean(jsonObj, Map.class);
    Country country = null;
    if (limitViolation.containsKey("Country")) {
        country = Country.valueOf(limitViolation.get("Country"));
    }
    float baseVoltage = Float.NaN;
    if (limitViolation.containsKey("BaseVoltage")) {
        baseVoltage = Float.parseFloat(limitViolation.get("BaseVoltage"));
    }
    float limitReduction = 1f;
    if (limitViolation.containsKey("LimitReduction")) {
        limitReduction = Float.parseFloat(limitViolation.get("LimitReduction"));
    }
    return new LimitViolation(limitViolation.get("Subject"),
            LimitViolationType.valueOf(limitViolation.get("LimitType")),
            Float.parseFloat(limitViolation.get("Limit")),
            limitViolation.get("LimitName"),
            limitReduction,
            Float.parseFloat(limitViolation.get("Value")),
            country,
            baseVoltage);
}
 
开发者ID:itesla,项目名称:ipst,代码行数:25,代码来源:OnlineDbMVStoreUtils.java

示例3: checkForDx

import net.sf.json.JSONSerializer; //导入依赖的package包/类
public ActionForward checkForDx(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) {
	String demographicNo = request.getParameter("demographicNo");
	String codingSystem = request.getParameter("codingSystem");
	String code = request.getParameter("code");
	
	boolean exists = dxResearchDao.activeEntryExists(Integer.parseInt(demographicNo), codingSystem, code);
	
	String str = "{'result':"+exists+"}";  
	JSONObject jsonArray = (JSONObject) JSONSerializer.toJSON(str);
       response.setContentType("text/x-json");
       try {
       	jsonArray.write(response.getWriter());
       }catch(IOException e) {
       	MiscUtils.getLogger().error("Error",e);
       }

	return null;
}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:19,代码来源:RenalAction.java

示例4: unspecified

import net.sf.json.JSONSerializer; //导入依赖的package包/类
public ActionForward unspecified(ActionMapping mapping, ActionForm form,HttpServletRequest request,HttpServletResponse response) throws Exception{
    String searchStr=request.getParameter("providerKeyword");
    if(searchStr==null){
        searchStr=request.getParameter("query");
    }
    if(searchStr==null){
        searchStr=request.getParameter("name");
    }        
   
    
    MiscUtils.getLogger().info("Search Provider " + searchStr);
    List provList=ProviderData.searchProvider(searchStr,true);
    Hashtable d=new Hashtable();
    d.put("results", provList);

    response.setContentType("text/x-json");
    JSONObject jsonArray=(JSONObject) JSONSerializer.toJSON(d);
    jsonArray.write(response.getWriter());
    return null;

}
 
开发者ID:williamgrosset,项目名称:OSCAR-ConCert,代码行数:22,代码来源:SearchProviderAutoCompleteAction.java

示例5: createWebHook

import net.sf.json.JSONSerializer; //导入依赖的package包/类
/**
 * Creates a web hook in Gogs with the passed json configuration string
 *
 * @param jsonCommand A json buffer with the creation command of the web hook
 * @param projectName the project (owned by the user) where the webHook should be created
 * @throws IOException something went wrong
 */
int createWebHook(String jsonCommand, String projectName) throws IOException {

    String gogsHooksConfigUrl = getGogsServer_apiUrl()
            + "repos/" + this.gogsServer_user
            + "/" + projectName + "/hooks";

    Executor executor = getExecutor();

    String result = executor
            .execute(Request.Post(gogsHooksConfigUrl).bodyString(jsonCommand, ContentType.APPLICATION_JSON))
            .returnContent().asString();
    JSONObject jsonObject = (JSONObject) JSONSerializer.toJSON( result );
    int id = jsonObject.getInt("id");

    return id;
}
 
开发者ID:jenkinsci,项目名称:gogs-webhook-plugin,代码行数:24,代码来源:GogsConfigHandler.java

示例6: isSourceArrayValid

import net.sf.json.JSONSerializer; //导入依赖的package包/类
/**
 * Validates the request parameter sourceArray
 *
 * @param sourceArray The request parameter sourceArray
 * @return true if validated
 */
private boolean isSourceArrayValid(String sourceArray) {
    JSONArray sourceJSON;
    try {
        sourceJSON = (JSONArray) JSONSerializer.toJSON(sourceArray);
    } catch (JSONException ex) {
        logger.error("JSONException : " + ex);
        return false;
    }
    if (!prepareLists(sourceJSON)) {
        throw new OperationFailedException("The requested resource(s) do not exist in the " + "repository. " +
                "Aborting operation.");
    }
    extensionsList = getListOfExtensionsFromSettings();
    return (extensionsList != null);
}
 
开发者ID:helicalinsight,项目名称:helicalinsight,代码行数:22,代码来源:DeleteOperationHandler.java

示例7: setRequestData

import net.sf.json.JSONSerializer; //导入依赖的package包/类
@Override
public void setRequestData(String data) {
    requestParameterJson = (JSONObject) JSONSerializer.toJSON(data);
    String downloadType = requestParameterJson.optString("type");
    // Set the content type for the response from the properties file
    this.contentType = (propertyMap.get(downloadType));

    if (downloadType == null || downloadType.isEmpty()) {
        //Default type being csv format
        this.fileExtension = ".csv";
        downloadType = "csv";
    } else {
        this.fileExtension = "." + downloadType;
    }

    String beanName = settingsDownloadMap.get(downloadType);
    iDownload = (IDownload) ApplicationContextAccessor.getBean(beanName);
    CacheManager = this.getCacheManager();
    CacheManager.setRequestData(data);
}
 
开发者ID:helicalinsight,项目名称:helicalinsight,代码行数:21,代码来源:DownloadCacheManager.java

示例8: testMarshalAndUnmarshal

import net.sf.json.JSONSerializer; //导入依赖的package包/类
@Test
public void testMarshalAndUnmarshal() throws Exception {
    InputStream inStream = getClass().getResourceAsStream("testMessage1.xml");
    String in = context.getTypeConverter().convertTo(String.class, inStream);

    MockEndpoint mockJSON = getMockEndpoint("mock:json");
    mockJSON.expectedMessageCount(1);
    mockJSON.message(0).body().isInstanceOf(byte[].class);

    MockEndpoint mockXML = getMockEndpoint("mock:xml");
    mockXML.expectedMessageCount(1);
    mockXML.message(0).body().isInstanceOf(String.class);

    Object json = template.requestBody("direct:marshal", in);
    String jsonString = context.getTypeConverter().convertTo(String.class, json);
    JSONObject obj = (JSONObject) JSONSerializer.toJSON(jsonString);
    assertEquals("JSONObject doesn't contain 7 keys", 7, obj.entrySet().size());

    template.sendBody("direct:unmarshal", jsonString);

    mockJSON.assertIsSatisfied();
    mockXML.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:SpringXmlJsonDataFormatTest.java

示例9: testSomeOptionsToJSON

import net.sf.json.JSONSerializer; //导入依赖的package包/类
@Test
public void testSomeOptionsToJSON() throws Exception {
    InputStream inStream = getClass().getClassLoader().getResourceAsStream("org/apache/camel/dataformat/xmljson/testMessage1.xml");
    String in = context.getTypeConverter().convertTo(String.class, inStream);

    MockEndpoint mockJSON = getMockEndpoint("mock:json");
    mockJSON.expectedMessageCount(1);
    mockJSON.message(0).body().isInstanceOf(byte[].class);

    Object json = template.requestBody("direct:marshal", in);
    String jsonString = context.getTypeConverter().convertTo(String.class, json);
    JSONObject obj = (JSONObject) JSONSerializer.toJSON(jsonString);
    assertEquals("JSON must contain 1 top-level element", 1, obj.entrySet().size());
    assertTrue("Top-level element must be named root", obj.has("root"));

    mockJSON.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:XmlJsonOptionsTest.java

示例10: testXmlWithTypeAttributesToJSON

import net.sf.json.JSONSerializer; //导入依赖的package包/类
@Test
public void testXmlWithTypeAttributesToJSON() throws Exception {
    InputStream inStream = getClass().getClassLoader().getResourceAsStream("org/apache/camel/dataformat/xmljson/testMessage4.xml");
    String in = context.getTypeConverter().convertTo(String.class, inStream);

    MockEndpoint mockJSON = getMockEndpoint("mock:json");
    mockJSON.expectedMessageCount(1);
    mockJSON.message(0).body().isInstanceOf(byte[].class);

    Object json = template.requestBody("direct:marshal", in);
    String jsonString = context.getTypeConverter().convertTo(String.class, json);
    JSONObject obj = (JSONObject) JSONSerializer.toJSON(jsonString);
    assertEquals("JSON must contain 1 top-level element", 1, obj.entrySet().size());
    assertTrue("Top-level element must be named root", obj.has("root"));

    mockJSON.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:XmlJsonOptionsTest.java

示例11: testNamespacesDropped

import net.sf.json.JSONSerializer; //导入依赖的package包/类
@Test
public void testNamespacesDropped() throws Exception {
    InputStream inStream = getClass().getClassLoader().getResourceAsStream("org/apache/camel/dataformat/xmljson/testMessage2-namespaces.xml");
    String in = context.getTypeConverter().convertTo(String.class, inStream);

    MockEndpoint mockJSON = getMockEndpoint("mock:json");
    mockJSON.expectedMessageCount(1);
    mockJSON.message(0).body().isInstanceOf(byte[].class);

    Object json = template.requestBody("direct:marshal", in);
    String jsonString = context.getTypeConverter().convertTo(String.class, json);
    JSONObject obj = (JSONObject) JSONSerializer.toJSON(jsonString);
    assertEquals("JSON must contain 1 top-level element", 1, obj.entrySet().size());
    assertTrue("Top-level element must be named root", obj.has("root"));
    // check that no child of the top-level element has a colon in its key,
    // which would denote that
    // a namespace prefix exists
    for (Object key : obj.getJSONObject("root").keySet()) {
        assertFalse("A key contains a colon", ((String) key).contains(":"));
    }

    mockJSON.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:XmlJsonOptionsTest.java

示例12: testTypeHintsToJSON

import net.sf.json.JSONSerializer; //导入依赖的package包/类
@Test
public void testTypeHintsToJSON() throws Exception {
    InputStream inStream = getClass().getClassLoader().getResourceAsStream("org/apache/camel/dataformat/xmljson/testMessage5-typeHints.xml");
    String in = context.getTypeConverter().convertTo(String.class, inStream);

    MockEndpoint mockJSON = getMockEndpoint("mock:jsonTypeHints");
    mockJSON.expectedMessageCount(1);
    mockJSON.message(0).body().isInstanceOf(byte[].class);

    Object json = template.requestBody("direct:marshalTypeHints", in);
    String jsonString = context.getTypeConverter().convertTo(String.class, json);
    JSONObject obj = (JSONObject) JSONSerializer.toJSON(jsonString);
    assertEquals("root.a must be number", Integer.valueOf(1), obj.getJSONObject("root").get("a"));
    assertEquals("root.b must be boolean", Boolean.TRUE, obj.getJSONObject("root").get("b"));

    mockJSON.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:XmlJsonOptionsTest.java

示例13: testPrefixedTypeHintsToJSON

import net.sf.json.JSONSerializer; //导入依赖的package包/类
@Test
public void testPrefixedTypeHintsToJSON() throws Exception {
    InputStream inStream = getClass().getClassLoader().getResourceAsStream("org/apache/camel/dataformat/xmljson/testMessage6-prefixedTypeHints.xml");
    String in = context.getTypeConverter().convertTo(String.class, inStream);

    MockEndpoint mockJSON = getMockEndpoint("mock:jsonPrefixedTypeHints");
    mockJSON.expectedMessageCount(1);
    mockJSON.message(0).body().isInstanceOf(byte[].class);

    Object json = template.requestBody("direct:marshalPrefixedTypeHints", in);
    String jsonString = context.getTypeConverter().convertTo(String.class, json);
    JSONObject obj = (JSONObject) JSONSerializer.toJSON(jsonString);
    assertEquals("root.a must be number", Integer.valueOf(1), obj.getJSONObject("root").get("a"));
    assertEquals("root.b must be boolean", Boolean.TRUE, obj.getJSONObject("root").get("b"));

    mockJSON.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:18,代码来源:XmlJsonOptionsTest.java

示例14: testUnmarshalJSONObject

import net.sf.json.JSONSerializer; //导入依赖的package包/类
@Test
public void testUnmarshalJSONObject() throws Exception {
    InputStream inStream = getClass().getResourceAsStream("testMessage1.json");
    String in = context.getTypeConverter().convertTo(String.class, inStream);
    JSON json = JSONSerializer.toJSON(in);

    MockEndpoint mockXML = getMockEndpoint("mock:xml");
    mockXML.expectedMessageCount(1);
    mockXML.message(0).body().isInstanceOf(String.class);

    Object marshalled = template.requestBody("direct:unmarshal", json);
    Document document = context.getTypeConverter().convertTo(Document.class, marshalled);
    assertEquals("The XML document has an unexpected root node", "o", document.getDocumentElement().getLocalName());

    mockXML.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:17,代码来源:XmlJsonDataFormatTest.java

示例15: testMarshalAndUnmarshalInline

import net.sf.json.JSONSerializer; //导入依赖的package包/类
@Test
public void testMarshalAndUnmarshalInline() throws Exception {
    InputStream inStream = getClass().getResourceAsStream("testMessage1.xml");
    String in = context.getTypeConverter().convertTo(String.class, inStream);

    MockEndpoint mockJSON = getMockEndpoint("mock:jsonInline");
    mockJSON.expectedMessageCount(1);
    mockJSON.message(0).body().isInstanceOf(byte[].class);

    MockEndpoint mockXML = getMockEndpoint("mock:xmlInline");
    mockXML.expectedMessageCount(1);
    mockXML.message(0).body().isInstanceOf(String.class);

    Object json = template.requestBody("direct:marshalInline", in);
    String jsonString = context.getTypeConverter().convertTo(String.class, json);
    JSONObject obj = (JSONObject) JSONSerializer.toJSON(jsonString);
    assertEquals("JSONObject doesn't contain 7 keys", 7, obj.entrySet().size());

    template.sendBody("direct:unmarshalInline", jsonString);

    mockJSON.assertIsSatisfied();
    mockXML.assertIsSatisfied();
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:24,代码来源:XmlJsonDataFormatTest.java


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